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条回答
趁早两清
2楼-- · 2020-02-02 04:33

In the manifest file Change:

    android:theme="@style/AppTheme" >
    android:theme="@style/Theme.AppCompat.NoActionBar"
查看更多
【Aperson】
3楼-- · 2020-02-02 04:34

This works for me

getSupportActionBar().hide();
查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-02-02 04:35

Best way is to use actionbar function setTitle() if you wish to show logo or have some other stuff in you actionBar but dont want to see name of the app, write this code in MainActivity.java or anywhere you wish to hide title in onCreate:

android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.full_white_logo_m); // display logo
actionBar.setTitle(""); // hide title

This way your app won't have reason to crash.

查看更多
劳资没心,怎么记你
5楼-- · 2020-02-02 04:36

I have faced the same problem as you, and solve this problem just by changing the class which I extended.

//you will get the app that does not have a title bar at the top.
import android.app.Activity;
public class MainActivity extends Activity
{}

//you will get the app that has title bar at top
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{}

I hope this will solve your problem.

查看更多
不美不萌又怎样
6楼-- · 2020-02-02 04:37
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

works in onCreate() when put before setContentView() is invoked.

otherwise it crashes

查看更多
We Are One
7楼-- · 2020-02-02 04:37

In AndroidManifest.xml of your application you'll find the android:theme for example set to @style/AppTheme

Now go to styles.xml, find the style tag, make sure that name is set to AppTheme the same as in manifest and set parent to android:Theme.Holo.Light.NoActionBar (also do this in styles(v21) if you have it in your project)

<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar">
    <!-- ... -->
</style>
查看更多
登录 后发表回答