Remove titlebar in xml

孤人 提交于 2019-12-11 19:21:51

问题


Im trying to remove the titlebar at the top of my app.

I know this can be done by adding, @android:style/Theme.NoTitleBar to the manifest. The thing is that this makes the Holo theme disappear on 3.0+ devices. Are there anyway I can remove the titlebar and keep the orginal theme?

-EDIT- Unforiunally this line @android:style/Theme.Holo.NoActionBar requires api level above 11.


回答1:


You can specify different default themes for different API levels.

In Android you have the directories values-v11 and values. The first one is for all Android 3.0 and above (if no other one with higher version is specified). The second is the default one.

In the styles.xml of values-v11 you define:

<style name="AppBaseTheme" parent="android:Theme.Holo.NoActionBar"></style>

and in the styles.xml of values:

<style name="AppBaseTheme" parent="android:Theme.NoTitleBar"></style>

If you put android:theme="@style/AppBaseTheme" in the <application> tag of the manifest you should keep the Holo theme on 3.0+ devices.




回答2:


You can try this:-

 @Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
...

}




回答3:


use bellow method before write setContentView()

 @Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
}



回答4:


Use below code in onCreate()

if(android.os.Build.VERSION.SDK_INT>11)
    setTheme(android.R.style.Theme.Holo.NoActionBar);
else
    setTheme(android.R.style.Theme_DeviceDefault_NoActionBar);


来源:https://stackoverflow.com/questions/17467134/remove-titlebar-in-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!