AndroidManifest - 为 activity 设置主题

AndroidManifest - Set theme for activity

我现在真的很沮丧,读了很多书 - 也许你能帮助我。 为什么 Android Studio 仍然向我显示带有标题栏的 "Main2Activity"?

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.martin.myapplication">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Main2Activity"
        android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
</application>

我知道这确实是个小问题,但我想不通...

我使用的来源:

https://developer.android.com/guide/topics/ui/look-and-feel/themes.html

Android theme not being set

Apply a theme to an activity in Android?

编辑 当前状态: enter image description here

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

正在工作,但禁用了每个 Activity!

的 ActionBar

目标:activity_main2 不应有 ActionBar。

已解决 这只是 Android Studio 的一个错误。在预览版中,它不会禁用 AppBar,但只要您在手机上播放该应用程序,它就会起作用!

要隐藏操作栏,请在 Values/Styles

中添加以下代码
<style name="CustomActivityThemeNoTitle" parent="@android:style/Theme.Light">
    <item name="android:windowNoTitle">true</item>
</style>

然后在您的 AndroidManifest.xml 文件中,在所需的 activity:

中添加以下代码
<activity android:name=".Main2Activity"
    android:theme="@style/CustomActivityThemeNoTitle"></activity>

或者,您可以在 activity 的 onCreate 方法中调用 this.requestWindowFeature(Window.FEATURE_NO_TITLE);。例如:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_signup);
    ...
}

试试这个

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