How do I remove the title bar in android studio?

2020-02-02 04:01发布

In my app there is this title bar at the top where the overflow menu would be, but I don't need settings and only have one screen. When I change the theme like described in many other questions I get the old 2.2 theme. I want to have the modern theme just without the bar at the top.

24条回答
Summer. ? 凉城
2楼-- · 2020-02-02 04:53

This works for me i hope this work for you as well

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
}
查看更多
▲ chillily
3楼-- · 2020-02-02 04:55

Go to styles.xml and change .DarkActionBar for .NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>

becomes

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

if colors are irrelevant to your app, you can actually go for

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />
查看更多
不美不萌又怎样
4楼-- · 2020-02-02 04:55
  1. open styles.xml
  2. insert
 <style name="no_title" parent="AppTheme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
 </style>

you can change name="---------"

  1. open Androidmaifest.xm

    find android:theme="@style/AppTheme" chang to android:theme="@style/no_title"

  2. click select Theme on menubar (it's green color near MainActivity)

    • click project Theme
    • click no_title (on you right hand Side)
    • click OK
查看更多
手持菜刀,她持情操
5楼-- · 2020-02-02 04:56

For Beginner Like Me. Just Do it what I say.From your Android Project.

app -> res -> values -> style.xml

replace this code

<resources>

<!-- 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>
</style>

</resources>

Enjoy.

查看更多
三岁会撩人
6楼-- · 2020-02-02 04:56

To simply remove the title bar (which means the bar contains your app name) from an activity, I simply add below line to that activity in the manifests\AndroidManifest.xml:

android:theme="@style/AppTheme.NoActionBar"

It should now look like below

<activity
  android:name=".MyActivity"
  android:theme="@style/AppTheme.NoActionBar"></activity>

Hope it'll be useful.

查看更多
放我归山
7楼-- · 2020-02-02 04:58

try: toolbar.setTitle(" ");

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle("");
    setSupportActionBar(toolbar);
}
查看更多
登录 后发表回答