Android Studio未应用我的设计更改

时间:2017-09-29 08:30:50

标签: android-studio kotlin manifest

我正在尝试通过删除操作栏或更改其标题来更改某些活动的主题。起初我正在使用设计选项卡中的AppTheme选项来完成它。但是,在网上搜索后,我知道我的方法是错误的,所以我继续使用AndroidManifest文件手动进行更改。不幸的是,它也没有用。这是我的清单文件的代码:

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

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <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"
                  android:label="Sign Up"/>

        <activity
            android:name=".Login"
            android:label="Log In"/>

        <activity android:name=".drawable.welcome">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".UserProfile"
                  android:theme="@style/AppTheme.NoActionBar"/>
        <activity android:name=".HomePage" >
        </activity>
    </application>

</manifest>

以下是我正在尝试更改的一些活动: Action Bar Title Changed Successfully Action Bar Title Didn't Change

我正在使用Android Studio 3.0 Preview和Kotlin。我希望你能提供帮助,因为如果不解决这个设计问题我就无法继续工作!

1 个答案:

答案 0 :(得分:0)

你可以两种方式修复问题。 1.对所有活动使用共同的一个主题,并使用代码隐藏和显示onCreate方法中的操作栏

   // Set up the toolbar
 val toolbar = findViewById(R.id.toolbar) as Toolbar
        setSupportActionBar(toolbar)
         var actionBar = supportActionBar

        //For hiding android actionbar
        actionBar.hide();

        //For showing android actionbar
        //actionBar.show();
  1. 将自定义样式用于您不希望在下面的示例中显示操作栏的活动我为应用程序级别执行了此操作,但您可以按照自己的方式使用其他任何活动
  2. <强> style.xml

    <resources>
        <style name = "AppTheme" parent = "android:Theme.Holo.Light.DarkActionBar">
            <!-- Customize your theme here. -->
        </style>
    
        <style name = "NoActionBar" parent = "@android:style/Theme.Holo.Light">
            <item name = "android:windowActionBar">false</item>
            <item name = "android:windowNoTitle">true</item>
        </style>
    
    </resources>
    

    <强>的AndroidManifest.xml

    <application
        android:allowBackup = "true"
        android:icon = "@drawable/ic_launcher"
        android:label = "@string/app_name"
        android:theme = "@style/NoActionBar"   <!--This is the important line-->
        >
        <activity