简体   繁体   English

我无法在android studio中更改活动主题

[英]I can't change the activity theme in android studio

I'm using the activity design to try to change the theme. 我正在使用活动设计来尝试更改主题。

Unfortunately, when I run the app on my phone, it consistently shows this blue color. 不幸的是,当我在手机上运行应用程序时,它始终显示这种蓝色。 I don't know why it's blue or where this theme came from. 我不知道为什么它是蓝色或这个主题来自哪里。 This issue only started appearing recently. 这个问题最近才开始出现。 Any help? 有帮助吗?

Here's the relevant code. 这是相关的代码。 Please keep in mind that this is simply an empty activity. 请记住,这只是一个空洞的活动。 I have not modified the code in any way. 我没有以任何方式修改代码。 For some reason android studio defaults to this behavior. 由于某种原因,android studio默认使用此行为。

To be clear, I tried changing the theme using the highlighted button in the second image. 为了清楚起见,我尝试使用第二张图片中突出显示的按钮更改主题。 No matter which theme I pick, all that changes is the activity view in the IDE. 无论我选择哪个主题,所有更改都是IDE中的活动视图。

AndroidManifest.xml AndroidManifest.xml中

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    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>
</application>

colors.xml colors.xml

<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>

styles.xml styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Screencap from phone Screencap来自手机

What it should look like 应该是什么样的

You need to change hex color value as what color you want in colors.xml like below 您需要在colors.xml中将十六进制颜色值更改为您想要的颜色,如下所示

<resources>
    <color name="colorPrimary">#d3d3d3</color>
    <color name="colorPrimaryDark">#a8a8a8</color>
</resources>

Change the parent theme as 将父主题更改为

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

instead 代替

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

Perhaps an easier way would be to create a different xml file to manage such issues. 也许更简单的方法是创建一个不同的xml文件来管理这些问题。 To do so, right click on your drawable folder-New -Drawable Resource File-Name.xml. 为此,右键单击drawable文件夹-New -Drawable Resource File-Name.xml。

Then go online to http://angrytools.com/gradient/ and genetate whichever theme you desire. 然后上网到http://angrytools.com/gradient/并根据你想要的主题进行基因测试。 Get the code generated and paste it in the xml file you created. 获取生成的代码并将其粘贴到您创建的xml文件中。

Next, within your layout tag within the activity xml file, place the following line 接下来,在活动xml文件中的布局标记内,放置以下行

android:background="@drawable/Name"

You can then modify your theme by editing the drawable file you created. 然后,您可以通过编辑您创建的可绘制文件来修改主题。 Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM