Reputation: 75
I am new for Android development and I want to hide title bar in my application.
I tried everything I can to hide the bar but the application either stopped or had nothing changed.
I ran the demo on a virtual device.It's a 5.4" FWVGA phone.
I've also tried to add
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
or
android:theme="@android:style/Theme.NoTitleBar(.Fullscreen)"
but unfortunately , the application stopped.
Please tell me how to hide the title bar.
Here is my java codes , layout file , AndroidManifest.xml and styles.xml.
package com.activitytest2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class FirstActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//1. getActionBar().hide();
//2. requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.first_layout);
Button button1 = (Button) findViewById(R.id.button_1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(FirstActivity.this,"You clicked button 1",Toast.LENGTH_SHORT).show();
}
});
}
}
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 1"/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.activitytest2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
Upvotes: 2
Views: 715
Reputation: 79646
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:
Upvotes: 0
Reputation: 641
go to simple way. just replace getActionBar().hide();
to getSupportActionBar().hide();
I hope this solution helps you.
"@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.first_layout);"
Upvotes: 2
Reputation: 1981
Replace your style with below:This will hide your actionbar too.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowNoTitle">true</item>
</style>
Upvotes: 0
Reputation: 716
Are you using AppCompat activity for that u need AppCompat theme. use this Theme.AppCompat.Light.NoActionBar
//add style file
<style name="Theme.SlamBook.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar"></style>
//add in menifest
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.SlamBook.NoActionBar">
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Upvotes: 0
Reputation: 4335
Just Try with,
requestWindowFeature(Window.FEATURE_NO_TITLE);
before the setContentView
. like,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.first_layout);
}
Upvotes: 0
Reputation: 75788
No need to add getActionBar().hide();
Just do this ,
Flag for the "no title" feature, turning off the title at the top of the screen.
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
For test case , add this in your style section
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
and make sure below in manifest
android:theme="@style/AppTheme"
you can try with,
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
//code that displays the content in full screen mode
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Upvotes: 1
Reputation: 1326
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
in onCreate() will remove your title bar.
Upvotes: 0