obsidian/笔记文件/2.笔记/Activity使用和透明化处理.md
2025-03-26 00:02:56 +08:00

2.7 KiB
Raw Permalink Blame History

#安卓

需要在AndroidManifest.xml中完成activity相关的添加其中theme主题选择的是 Theme.NoTitleBar 无标题

    <application>

        <activity android:name=".SurveyMonkey_SDK_Activity"
                android:label="Simple Activity"
                android:theme="@android:style/Theme.NoTitleBar"/>
    </application>

添加后的文本样式:

!Pasted image 20241115095829.png

然后,在 Activity活动类的onCreate中添加以下逻辑处理透明化相关

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); // 无触摸
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  // 全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent); // 设置透明背景

样式效果:

!Pasted image 20241115100108.png

提供给外部调用的是一个static静态函数 需要注意的是,如果包含 JSONObject 结构体的数据,是需要跟随 throw异常监听 JSONException

    public static void launchActivity(Activity context,String hash,JSONObject jsonStr,boolean _isResponse,boolean _getResponse,String _Response_GameObject_Str,String _Response_Function_Str)  throws JSONException
    {
        SURVEY_HASH_Str = hash;
        survey_json_Str = jsonStr;

        Response_GameObject_Str = _Response_GameObject_Str;
        Response_Function_Str = _Response_Function_Str;
        isResponse = _isResponse;
        getResponse = _getResponse;
        
        Intent intent = new Intent(context, SurveyMonkey_SDK_Activity.class);
        context.startActivity(intent);
    }

外部调用的相关逻辑这里是提取到unity相关的Activity作为父活动调用创建即可

            Activity activity = UnityActivity.getActivity();
            boolean _isResponse = true;
            if(_Response_Function_Str == null || _Response_Function_Str.isEmpty() || _Response_GameObject_Str == null || _Response_GameObject_Str.isEmpty()) 
            {
                _isResponse = false;
            }
            SurveyMonkey_SDK_Activity.launchActivity(activity,SURVEY_HASH,jsonObject_surveyMonkey,_isResponse,_getResponse,_Response_GameObject_Str,_Response_Function_Str);

全局检索UnityActivity.java可以看到,具体逻辑:

!Pasted image 20241115110718.png