Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
696 views
in Technique[技术] by (71.8m points)

android - Why is AppTheme.NoActionBar not working?

I've created an Android app in Android Studio, and it has created these styles by default:

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

However, in an activity, I try to set this as a theme:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   ...
android:theme="@style/AppTheme.NoActionBar">

But when I run the app I'm getting the action bar:

enter image description here

Why am I getting an action bar? Am I doing something obviously wrong, or is Android Studio, Google's official IDE for it's own platform, trying to confuse/mislead its developers?

Here is my activity code, there's nothing in it that can cause the action bar to appear by itself:

public class WelcomeActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.activity_welcome);
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try something like this:

<style name="AppTheme.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
  </style>

and set this as the theme of your activity in the manifest, that is:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...