有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java试图摆脱所有活动的标题栏

我试图在我的应用程序的每个活动中去掉标题栏,但它在启动时崩溃了。我只修改了清单,没有涉及任何onCeate()方法。相关舱单:

<uses-sdk
        安卓:minSdkVersion="11"
        安卓:targetSdkVersion="21" />

    <uses-permission 安卓:name="安卓.permission.INTERNET" />
    <uses-permission 安卓:name="安卓.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission 安卓:name="安卓.permission.WRITE_INTERNAL_STORAGE" />

    <application
        安卓:allowBackup="true"
        安卓:icon="@drawable/ic_launcher"
        安卓:label="@string/app_name"
        安卓:theme="@安卓:style/Theme.NoTitleBar" >
        <activity
            安卓:name=".MainActivity"
            安卓:label="@string/app_name"
            安卓:screenOrientation="landscape"
            安卓:theme="@安卓:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            安卓:name=".UpgradeActivity"
            安卓:label="@string/title_activity_upgrade"
            安卓:screenOrientation="landscape"
            安卓:theme="@安卓:style/Theme.NoTitleBar.Fullscreen">
        </activity>
        <activity
            安卓:name=".StatsActivity"
            安卓:label="@string/title_activity_stats"
            安卓:screenOrientation="landscape"
            安卓:theme="@安卓:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            安卓:name=".PrestiegeActivity"
            安卓:label="@string/title_activity_prestiege"
            安卓:screenOrientation="landscape"
            安卓:theme="@安卓:style/Theme.NoTitleBar.Fullscreen">
        </activity>
    </application>

LogCat:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.company/com.example.company.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

-谢谢


共 (1) 个答案

  1. # 1 楼答案

    在你的风格中加入这个。xml

    <style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!  Customize your theme here.  >
            <item name="colorPrimary">@color/color_primary</item>
            <item name="colorPrimaryDark">@color/color_primary_dark</item>
            <item name="colorAccent">@color/accent_color</item>
    </style>
    

    在你的舱单上:

    android:theme="@style/MyTheme" 
    

    在你的活动中扩展你的活动