我知道如何将主题应用于整个应用程序,但是我该去哪里仅将主题应用于单个活动?
<activity>
标签内部包含android:theme
来为任何活动应用主题。<activity android:theme="@android:style/Theme.Dialog">
<activity android:theme="@style/CustomTheme">
onCreate()
方法中调用setContentView()
和super.onCreate()
方法之前使用setTheme()
方法。要在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);
在Manifest.xml中的应用程序范围内设置(所有活动):
<application
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
在 Manifest.xml 中设置 Activity 范围(单个 Activity):
<activity
android:theme="@android:style/Theme.Holo"
android:theme="@style/MyTheme">
要创建自定义主题,您需要在themes.xml文件中声明主题,并在styles.xml文件中设置样式。
android:theme
属性? - Flame of udunstyles.xml
文件中描述的自定义主题的语法。 在实际的AndroidManifest.xml
文件中,每个部分只使用其中一个,而不是两个都使用。 - Soren Stoutnerstyles.xml
中创建一个空主题,然后使用语法android:theme=@style/MyBlankTheme
。 - Soren StoutnersetContentView()
之前,调用setTheme(android.R.style...)
,将“...”替换为您需要的主题(例如:Theme、Theme_NoTitleBar等)。如果您使用的是自定义主题,则替换整个内容,这样您就会得到setTheme(yourThemesResouceId)
。
tools:context=".YourAtivityName"
。 - Faisal Naseer