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:
In your onCreate
method, use the following snippet:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
You just need to change AppTheme
style in Style.xml if you replace the definition from DarkActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to NoActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
the AppTheme defined in AndroidManifast.xml
In my case, if you are using android studio 2.1, and your compile SDK version is 6.0, then just go to your manifest.xml file, and change the following code:
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lesterxu.testapp2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is the snip shoot(see the highlight code):
when i tried to use all those high upvoted answers my app always crashed. (i think it has something to do with the "@android:style"?)
The best solution for me was to use the following:
android:theme="@style/Theme.AppCompat.NoActionBar"
No header / title bar anymore. Just place it in the <application>...</application>
or <activity>...</activity>
depending if you (don't) want it in the whole app or just a specific activity.
Add this style to your style.xml file
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
After that reference this style name into your androidManifest.xml in perticular activity in which you don't want to see titlebar, as like below.
<activity android:name=".youractivityname"
android:theme="@style/AppTheme.NoActionBar">
</activity>
Or if you want to hide/show the title bar at any point:
private void toggleFullscreen(boolean fullscreen)
{
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen)
{
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
else
{
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
getWindow().setAttributes(attrs);
}