How to Hide the Title Bar For an Activity in Xml With Existing Custom Theme

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

I now did the following.

I declared a style inheriting everything from my general style and then disabling the titleBar.

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

Now I can set this style to every Activity in which I want to hide the title bar overwriting the application wide style and inheriting all the other style informations, therefor no duplication in the style code.

To apply the style to a particular Activity, open AndroidManifest.xml and add the following attribute to the activity tag;

<activity
android:theme="@style/generalnotitle">

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

I now did the following.

I declared a style inheriting everything from my general style and then disabling the titleBar.

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

Now I can set this style to every Activity in which I want to hide the title bar overwriting the application wide style and inheriting all the other style informations, therefor no duplication in the style code.

To apply the style to a particular Activity, open AndroidManifest.xml and add the following attribute to the activity tag;

<activity
android:theme="@style/generalnotitle">

How to remove title bar from the android activity?

Try this:

this.getSupportActionBar().hide();

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

try
{
this.getSupportActionBar().hide();
}
catch (NullPointerException e){}

setContentView(R.layout.activity_main);
}

Android Hide or Show Title Bar from the Activity and Fragment

First Change your App theme from res/value/styles.xml to this

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
//leave everything as it is
</style>

After that Add toolbar in your Activity's XML Layout

 <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:background="@color/colorAccent"
app:titleTextColor="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content">

//add your toolbar design here
</toolbar>

Now finally set up your toolbar in Activity Class

public class MyActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_activity_main);

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);

//need to set toolbar before calling getSupportActionBar
setSupportActionBar(toolbar);

//Now show or hide according to your need
getSupportActionBar().hide();
getSupportActionBar().show();


}
}

Same would be applicable for fragment but for fragment you need to call view first

Toolbar toolbar = getView().findViewById(R.id.toolbar);

How to hide title bar in Main Activity : I'm Using Android Studio

May I know what is your Android Studio version? When you create the activity, you will have this value in your styles.xml

    <style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

Check on your res > values > styles.xml, add it if there is no value like above. Then go to your manifest, add android:theme="@style/AppTheme.NoActionBar" in your activity tag.

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation"
android:theme="@style/AppTheme.NoActionBar">

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>


</intent-filter>

</activity>

For new version of Android Studio, styles.xml has been replaced to themes.xml.

How to hide the title bar for main Activity?

Set your theme for your main activity to Theme.AppCompat.Light.NoActionBar, and set your theme for your application to Theme.AppCompat.Light. If a theme is not explicitly set for an activity, it'll use the theme defined in the application tag.

how to remove the title of my activity when I add a button navigation?

Try this

this.getSupportActionBar().hide();

To hide entire ActionBar

Or you can try this ON YOUR activity

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

It will hide your text only

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

I now did the following.

I declared a style inheriting everything from my general style and then disabling the titleBar.

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

Now I can set this style to every Activity in which I want to hide the title bar overwriting the application wide style and inheriting all the other style informations, therefor no duplication in the style code.

To apply the style to a particular Activity, open AndroidManifest.xml and add the following attribute to the activity tag;

<activity
android:theme="@style/generalnotitle">

Hide title of an activity with Dialog theme

Dialog theme do not have any ActionBar, use Theme.AppCompat.Light.

If you still want to use the Dialog theme and want to hide the title bar, call supportRequestWindowFeature(Window.FEATURE_NO_TITLE); immediately after super.onCreate.



Related Topics



Leave a reply



Submit