如何阻止app_name在标题栏中闪现
常见自定义titlebar的方法是在values文件夹中新建一个我们自己的titlebar主题,例如:
values/custom_styles.xml:
<?xml version="1.0" encoding="utf-8"?><resources> <style name="TitlebarBackgroundStyle"> <item name="android:background">@drawable/titlebar</item> </style> <style name="Theme.MyCustomTheme" parent="android:Theme"> <item name="android:windowTitleBackgroundStyle">@style/TitlebarBackgroundStyle</item> <item name="android:windowTitleSize">45dp</item> </style></resources>
<activity android:name=".MyTitleBar" android:label="@string/app_name" android:theme="@style/Theme.MyCustomTheme" //注意添加与此
requestWindowFeature(Window.FEATURE_NO_TITLE);
android:theme="@android:style/Theme.NoTitleBar"
requestWindowFeature(Window.FEATURE_NO_TITLE);好使得多。但是问题来了,如果我还想要app呈现我自定义的标题栏怎么办呢?
setTheme(android.R.style.Theme);
protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsetTheme(R.style.MyCustomTheme);//注意这一句的位置super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);setContentView(R.layout.progressbar_test);getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, // 注意顺序 R.layout.title);