How to hide the title bar for an Activity in XML with existing custom theme

前端 未结 30 1675
误落风尘
误落风尘 2020-11-22 03:28

I want to hide the titlebar for some of my activities. The problem is that I applied a style to all my activities, therefore I can\'t simply set the theme to @android:

相关标签:
30条回答
  • 2020-11-22 03:31

    the correct answer probably is to not extend ActionbarActivity rather extend just Activity


    if you still use actionbar activity seems this is working:

    @Override
    protected void onCreate(Bundle savedInstanceState) {          
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide(); //<< this
        setContentView(R.layout.activity_main);
    }
    

    seems this works too:

    styles.xml:
    
       <style name="AppBaseTheme" parent="Theme.AppCompat.Light" >
              <item name="android:windowNoTitle">true</item>   <!-- //this -->     
       </style>
    

    i could do like as Scott Biggs wrote. this kind of works. except there is no theme then. i mean the settings menu's background is transparent:

    just change

    public class MainActivity extends ActionBarActivity {
    

    to Activity or FragmentActivity

    public class MainActivity extends Activity  {
    

    however i could make it look good enough using material design and not remove the actionbar: https://gist.github.com/shimondoodkin/86e56b3351b704a05e53

    1. set icon of application
    2. set colors of action bar to match design.
    3. set icon to settings menu
    4. add more icons (buttons on top)

    it is by example of material design compatibility actionbar styling.

    0 讨论(0)
  • 2020-11-22 03:34

    Just use getActionBar().hide(); in your main activity onCreate() method.

    0 讨论(0)
  • 2020-11-22 03:37

    Add

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

    inside AppTheme (styles.xml)

    0 讨论(0)
  • 2020-11-22 03:37

    I'm using a support widget Toolbar v7. So, in order to be able to delete or hide the Title we need to write this.

    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);
    
    //Remove¡ing title bar
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    
    0 讨论(0)
  • 2020-11-22 03:38

    For AppCompat, following solution worked for me:

    Add new theme style with no action bar in your styles.xml and set parent="Theme.AppCompat.NoActionBar".

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/colorPrimary</item>
    
    </style>
    


    Now implement the same theme style to your splash screen activity in androidManifest.xml

    <activity
            android:name=".ActivityName"
            android:theme="@style/SplashTheme"> // apply splash them here 
    
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    </activity>
    

    Here is result:

    0 讨论(0)
  • First answer is amphibole. here is my explain: add:

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    

    in oncreate() method.

    before:

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);
    

    (not just before setContentView) if don't do this u will get forceclose. +1 this answer.

    0 讨论(0)
提交回复
热议问题