Activity动态设置主题

android:theme 与 setTheme()设置透明效果并不同

一、在Manifest中设置主题

1.设置Application的主题在中添加android:theme=“@android:style/Theme.Translucent.NoTitleBar”

2.设置Activity的主题

在中添加 android:theme=“@android:style/Theme.Translucent.NoTitleBar”

Application的Theme默认是全局的,除非重写了Activity的Theme

二、在代码中动态设置主题

关键方法:setTheme(int resId)

这个方法是Activity中的一个方法

1.setTheme需要写在super.onCreate()前面setTheme(…);super.onCreate(savedInstanceState);setContentView(R.layout.Default);有效

2.setTheme需要写在super.onCreate()与setContentView()中间super.onCreate(savedInstanceState);setTheme(…);setContentView(R.layout.my_layout);有效

3.setTheme写在setContentView()后面无效

可以直接重写setTheme方法,该方法默认会在onCreate之前调用

setTheme->onCreate

三、问题点,设置透明主题时调用setTheme无效

通过二方法设置透明主题时,就会出现问题,主题设置没有效果,都是不起作用的-_-

通过现象可以总结如下

  1. 当activity通过动态设置主题时,设置透明的主题是不可用的。
  2. 当activity通过动态设置主题时,设置常规的主题是可行的。
  3. 当activity manifest中设置的主题是透明时,动态设置主题是可行的
  4. 当activity manifest中设置的主题不是透明时,动态设置主题为透明是不可行的

上面问题的解决方式

1.在AndroidMainfest.xml设置透明主题

android:theme=“@android:style/Theme.Translucent.NoTitleBar”

2.在Activity中调用setTheme方法

上面问题的解决方式

1.在AndroidMainfest.xml设置透明主题

android:theme=“@android:style/Theme.Translucent.NoTitleBar”

Android 隐式启动匹配原则

1、Intent中只能包含一个Action,可以包含多个Category;

2、清单文件中一个Activity可配置多个IntentFilter, 一个IntentFilter可包含多个

Action,多个Category,但是只能包含一个data;

3、Intent若含有Action,IntentFilter中包含多个Action,只要Intent中的Action与IntentFilter中的任一一个Action匹配,则算匹配成功;

4、Intent中若含有category,则这些category必须属于intentFilter中的category的子集,不管intentFilter中配置了多少category,Intent只需携带其子集数量的category即可匹配。

PS:IntentFilter中必须包含:categoryandroid:name=“android.intent.category.DEFAULT”/因为使用隐式意图的Intent中会添加默认的Category,即上图中的category值,如IntentFilter中不添加上图的Category,则匹配不成功,会爆出android.content.ActivityNotFoundException: No Activity found to handle Intent { act=xxxxxxxx }异常,但是我其实不太明白,为什么入口Activity中不需要这个默认的Category,希望有知道的能提点一下。

5、若清单文件中一个Activity配置了多个IntentFilter,Intent只需与其中一个IntentFilter中的内容相匹配即可,但不可跨越多个IntentFilter去匹配。

6、Data包含Scheme,Host,Port,Path和Type五部分,Intent中Data和Type是分开设置的,且会按照设置顺序后设置Type或Data会覆盖前设置的Data或type,如果要让Intent中Data和Type共同存在需要使用setDataAndType(Uri data,String type);的API同时设置。Intent中的Data的5个组成部分必须是IntentFilter中5个部分的自己,才算匹配。

OPENGL

不能在xml中引用GLSurfaceView

<GLSurfaceView
android:id=“@+id/gl_view”
android:layout_width=“match_parent”
android:layout_height=“match_parent”/>
Caused by: java.lang.ClassNotFoundException: Didn’t find class “android.view.GLSurfaceView” on path: DexPathList[[zip file “/data/app/jun.opgl-2/base.apk”],nativeLibraryDirectories=[/data/app/jun.opgl-2/lib/arm64, /vendor/lib64, /system/lib64]]
<android.opengl.GLSurfaceView
android:id=“@+id/gl_view”
android:layout_width=“match_parent”
android:layout_height=“match_parent”/>
java.lang.NullPointerException: Attempt to invoke virtual method ‘void android.opengl.GLSurfaceView$GLThread.surfaceCreated()’ on a null object reference
解决办法 在调用处不要忘记setRenderer
setContentView(R.layout.activity_main);
mGLView = (GLSurfaceView) findViewById(R.id.gl_view);
mGLView.setRenderer(new GLSurfaceView.Renderer());

GLES2.0需要权限