Marissa
Marissa

Reputation: 215

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.

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.

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

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

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

What it should look like

Upvotes: 1

Views: 5415

Answers (2)

Tom K
Tom K

Reputation: 11

Perhaps an easier way would be to create a different xml file to manage such issues. To do so, right click on your drawable folder-New -Drawable Resource File-Name.xml.

Then go online to http://angrytools.com/gradient/ and genetate whichever theme you desire. Get the code generated and paste it in the xml file you created.

Next, within your layout tag within the activity xml file, place the following line

android:background="@drawable/Name"

You can then modify your theme by editing the drawable file you created. Hope this helps

Upvotes: 1

iSrinivasan27
iSrinivasan27

Reputation: 1426

You need to change hex color value as what color you want in colors.xml like below

<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">

Upvotes: 2

Related Questions