Par*_*ani 142
您可以通过在清单文件中包含android:theme内部来将主题应用于任何活动<activity>.
例如:
<activity android:theme="@android:style/Theme.Dialog"><activity android:theme="@style/CustomTheme">如果你想以编程方式设置主题,那么setTheme()在调用方法setContentView()和super.onCreate()方法内部之前使用onCreate().
liv*_*ove 30
要在Activity.java中以编程方式设置它:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MyTheme); // (for Custom theme)
setTheme(android.R.style.Theme_Holo); // (for Android Built In Theme)
this.setContentView(R.layout.myactivity);
Run Code Online (Sandbox Code Playgroud)
要在Manifest.xml中设置应用程序范围(所有活动):
<application
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
Run Code Online (Sandbox Code Playgroud)
要在Manifest.xml中设置活动范围(单个活动):
<activity
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
Run Code Online (Sandbox Code Playgroud)
要构建自定义主题,您必须在themes.xml文件中声明主题,并在styles.xml文件中设置样式.
在你打电话之前setContentView(),打电话setTheme(android.R.style...),只需用你想要的主题替换......(Theme,Theme_NoTitleBar等).
或者,如果您的主题是自定义主题,则替换整个主题,以便获得 setTheme(yourThemesResouceId)
| 归档时间: |
|
| 查看次数: |
104488 次 |
| 最近记录: |