在我的应用程序中,我希望除带有材料设计滑动选项卡的Activity之外的所有Activity都具有ActionBar
。如果要制作材质设计滑动选项卡,则需要以我的风格使用:
parent="Theme.AppCompat.Light.NoActionBar"
但是有了这个代码,我就不会再ActionBar
进行其他我想要的活动了。
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
</resources>
tool_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/ColorPrimary"
android:elevation="2dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
xmlns:android="http://schemas.android.com/apk/res/android" />
那么我应该在资源中创建两种样式还是什么?
最好的方法是将其添加到您的AndroidManifest文件中。您可以通过将主题应用到任何活动的android:主题里面<活动>清单文件中。
例如:
<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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句