开发者

How disable / remove android activity label and label bar?

开发者 https://www.devze.com 2023-01-29 05:59 出处:网络
Is there anyway to remove activity label bar and label itself which is set by default from application label?

Is there anyway to remove activity label bar and label itself which is set by default from application label? I'd like to have whole layout from my design and need to remove the lab开发者_如何学Pythonel bar and label which is in TOP layout.


You can achieve this by setting the android:theme attribute to @android:style/Theme.NoTitleBar on your <activity> element in your AndroidManifest.xml like this:

<activity android:name=".Activity"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


If your application theme is AppTheme(or anything else), then in styles.xml add the following code:

<style name="HiddenTitleTheme" parent="AppTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
 </style>

Then in manifest file add the following in the activity tag for which you want to disable activity label:

android:theme="@style/HiddenTitleTheme"


public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  

        //set up notitle 
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        //set up full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
                WindowManager.LayoutParams.FLAG_FULLSCREEN);  

        setContentView(R.layout.main);  
} 


I am not 100% sure this is what you want but if you are referring to the title bar (the little gray strip at the top), you can remove/customize it via your manifest.xml file...

<activity android:name=".activities.Main"
          android:theme="@android:style/Theme.NoTitleBar">


you can try this

 ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayShowTitleEnabled(false);


You have two ways to hide the title bar by hiding it in a specific activity or hiding it on all of the activity in your app.

You can achieve this by create a custom theme in your styles.xml.

<resources>
    <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

If you are using AppCompatActivity, there is a bunch of themes that android provides nowadays. And if you choose a theme that has .NoActionBaror .NoTitleBar. It will disable you action bar for your theme.

After setting up a custom theme, you might want to use the theme in you activity/activities. Go to manifest and choose the activity that you want to set the theme on.

SPECIFIC ACTIVITY

AndroidManifest.xml

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name">

    <activity android:name=".FirstActivity"
        android:label="@string/app_name"
        android:theme="@style/MyTheme">
    </activity>
</application>

Notice that I have set the FirstActivity theme to the custom theme MyTheme. This way the theme will only be affected on certain activity. If you don't want to hide toolbar for all your activity then try this approach.

The second approach is where you set the theme to all of your activity.

ALL ACTIVITY

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyTheme">

    <activity android:name=".FirstActivity"
        android:label="@string/app_name">
    </activity>
</application>

Notice that I have set the application theme to the custom theme MyTheme. This way the theme will only be affected on all of activity. If you want to hide toolbar for all your activity then try this approach instead.


There is a code here that does it.

The trick is at this line:

 title.setVisibility(View.GONE);


There's also a drop down menu in the graphical layout window of eclipse. some of the themes in this menu will have ".NoTitleBar" at the end. any of these will do trick.


In my case, the others answers was not enough...

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

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
</application>

Tested on Android 4.0.3 API 15.


Whenever I do rake run:android,

my Androidmenifest.xml file is built-up again so my changes done

for NoTitlebar no more persist.

Rather than user adroid_title: 0

This helped me.

edit your build.yml

android:
  android_title: 0
  #rest of things 
  #you needed 


This one.

android:theme="@style/android:Theme.NoTitleBar"


you can use this in your activity tag in AndroidManifest.xml to hide label

android:label=""


IF you are using Android Studio 3+ This will work: android:theme="@style/Theme.AppCompat.NoActionBar"

@android:style/Theme.NoTitleBar will not support in new API and force you app close.


First way set the activity theme to NoTitleBar

 android:theme="@style/android:Theme.NoTitleBar"

Second way to ignore it

tools:ignore="SpeakableTextPresentCheck"


In your project "res/values/themes" edit style tag attribute for parent from

parent="Theme.MaterialComponents.DayNight.DarkActionBar"

to:

parent="Theme.MaterialComponents.DayNight.NoActionBar"

do this for both theme.xml files, it will remove ActionBar and keep default theme.


with your toolbar you can solve that problem. use setTitle method.

 Toolbar   mToolbar = (Toolbar) findViewById(R.id.toolbar);
  mToolbar.setTitle("");
  setSupportActionBar(mToolbar);

super easy :)

0

精彩评论

暂无评论...
验证码 换一张
取 消