How to disable action bar permanently

2019-01-01 08:48发布

I can hide the action bar in honeycomb using this code:

getActionBar().hide();

But when the keyboard opens, and user copy-pastes anything, the action bar shows again. How can I disable the action bar permanently?

25条回答
低头抚发
2楼-- · 2019-01-01 09:11
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    getSupportActionBar().hide();
}
查看更多
皆成旧梦
3楼-- · 2019-01-01 09:11

Go to styles.xml Change this DarkActionBar to NoActionBar

style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
查看更多
泛滥B
4楼-- · 2019-01-01 09:11

Another interesting solution where you want to retain the ViewPager while removing the action bar is to have a style as show

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/NoActionBarStyle</item>
    <item name="android:windowContentOverlay">@null</item>
</style>
<style name="NoActionBarStyle" parent="android:Widget.Holo.ActionBar">
    <item name="android:backgroundSplit">@null</item>
    <item name="android:displayOptions"></item>
</style>

This is the way most of the Dialer applications in android is showing the ViewPager without the action bar.

Ref: https://github.com/CyanogenMod/android_packages_apps_Dialer

查看更多
梦醉为红颜
5楼-- · 2019-01-01 09:11

There are two ways to disable ActionBar in Android.

requestWindowFeature(Window.FEATURE_NO_TITLE); 
setContentView(R.layout.activity_main); 
查看更多
公子世无双
6楼-- · 2019-01-01 09:11

I would like to post rather a Designer approach to this, this will keep design separate from your business logic:

Step 1. Create new style in (res->values->styles.xml) : Basically it is copy of your overall scheme with different parent - parent="Theme.AppCompat.Light.NoActionBar"

<!-- custom application theme. -->
    <style name="MarkitTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:windowNoTitle">true</item>
    </style>

Step 2: In your AndroidManifest.xml, add this theme to the activity you want in: e.g. I want my main activity without action-bar so add this like below:

<activity android:name=".MainActivity"
            android:theme="@style/MarkitTheme">

This is the best solution for me after trying a lot of things.

查看更多
闭嘴吧你
7楼-- · 2019-01-01 09:15

If you want to get full screen without actionBar and Title.

Add it in style.xml

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
      <item name="windowActionBar">false</item>
      <item name="windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
</style>

and use the style at manifest.xml.

android:theme="@style/AppTheme.NoActionBar" 
查看更多
登录 后发表回答