Android Dialog Divider Color - colors

I'm trying to make the dialog divider color lime.
My theme is already defined in android manifest and all. I defined the color lime in color.xml as well.
However, the divider is still not changing color from the default blue of the holo light theme.
Here is my themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyCustomTheme" parent="android:Theme.Holo.Light.NoActionBar">
<item name="android:textColor">#3DE400</item>
<item name="android:divider">#color/lime</item>
</style>
</resources>
Here is my color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="lime">#3DE400</color>
</resources>
Please Help Me..

This is a style, so it should be in your styles.xml, not themes.xml. Also, make sure it's linked to somewhere in there so the app knows to use it. Otherwise you're just defining the style, but it's not being used. An option is instead of defining your own style, simply customize the existing one. E.g.:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.Holo.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#3DE400</item>
<item name="android:divider">#color/lime</item>
</style>

Related

Is it possible to get an uncropped splash screen in Android 12?

On Android versions older than Android 12 I am easily able to construct a splash screen with an image which is not cropped. For example like this on Android 11:
However, Android 12 introduced a new Splash Screen API and I can't figure out how to reproduce the splash screen above in Android 12. It seems that it is always cropped and turns out like this on Android 12:
This is my android/src/main/res/values/styles.xml for older Android versions (e.g. Android 11):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">#drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
This is my android/src/main/res/values-v31/styles.xml for Android 12:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowSplashScreenAnimatedIcon">#drawable/launch_background</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="NormalTheme" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
The only difference between the two styles.xml is that I use android:windowSplashScreenAnimatedIcon for Android 12 and android:windowBackground for older Android versions as stated in the documentation for the new splash screen API (https://developer.android.com/guide/topics/ui/splash-screen).
Both styles.xml use #drawable/launch_background which is defined in android/src/main/res/drawable/launch_background.xml as follows:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:gravity="fill" android:src="#drawable/background"/>
</item>
<item>
<bitmap android:gravity="center" android:src="#drawable/splash"/>
</item>
</layer-list>
#drawable/background is just a .png with a single white pixel (1x1) and splash.png (1280x721) is the actual image I want to show in the splash screen which should not be cropped. I uploaded both files here: https://imgur.com/a/IzyYAwP
With the new Android 12 Splash Screen API, is it even possible to get a splash screen which is identical to the result I got with Android 11 (no cropping of the background image)? If yes, how is that possible?
No, it's not possible. The goal of the new splash screen is to unify the Splash Screen UX and the cropping is part of the design.

Changing actionbar color not working

I'm trying to change my action bar color to royal blue but it stays black despite everything I try. I've set the color code in my color.xml file and the theme is set to AppTheme in AndroidManifest.xml. I don't know what else could cause it to not work. Here is my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar">
<item name="android:background">#color/royal_blue</item>
</style>
It is recommended to use "colorPrimary" for configuring action bar color. You can use following files for styles configuration.You are recomended to use Toolbar to act as ActionBar
values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:textColorSecondary">#color/textColorSecondary</item>
</style>
<!-- Application theme to be used -->
<style name="AppTheme" parent="AppTheme.Base"></style>
</resources>
values-v22/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:colorAccent">#color/accentColor</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:textColorSecondary">#color/textColorSecondary</item>
</style>
</resources>
Please note to create another folder in in res folder named values-v22.This will be used by Lollipop devices.And values/styles.xml will be used by pre-lollipop devices.

Android action bar not reflecting color change

I've read numerous answers regarding changing the color of the action bar, but I can't seem to get it to work. Here's what I have:
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:windowBackground">#color/actionBarBackground
</item>
</style>
</resources>
I've also tried
<item name="android:Background">#F33</item>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
You are changing the android:windowBackground not the background of your ActionBar.
In any case, starting with the AppCompat v21+, you can use a new way to customize your ActionBar.
All of your Activities must extend from AppCompatActivity
All of your themes (that want an ActionBar/Toolbar) must inherit from Theme.AppCompat.
Just use a theme like this:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s color theming attrs -->
<item name="colorPrimary">#color/my_awesome_red</item>
<item name="colorPrimaryDark">#color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>
The current version of AppCompat is 23. It requires API23 to compile the project.
The following seems to have done the trick. I found it here Change Background color of the action bar using AppCompat
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:background">#color/actionBarBackground</item>
<item name="background">#color/actionBarBackground</item>
</style>
However, now my android:label in my manifest file is being covered by the background color, so I added
<item name="android:displayOptions">showTitle</item>
<item name="displayOptions">showTitle</item>

AppCompat ActionBar Background Color

I have this style.xml inside my Android app:
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<style name="OrangeTheme" parent="#style/Theme.AppCompat">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/OrangeTheme.OrangeActionBar</item>
<item name="android:windowActionBar">true</item>
</style>
<style name="OrangeTheme.OrangeActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#color/orange</item>
<item name="background">#color/orange</item>
<item name="android:backgroundStacked">#color/orange</item>
<item name="android:backgroundSplit">#color/orange</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/black</item>
</style>
I have searched StackOverflow and Google, but nothing helped. I wasn't able to change the ActionBar background color.
Inside my MainActivity, I use this code:
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
I tried not to use AppCompat, but then my name has a lot of errors. It extends ActionBarActivity. If I change it to FragmentActivity I can't use getSupportActionBar() and without it my getActionBar(), is always null.
minSdkVersion 19
targetSdkVersion 21
So right now I am not able to change it. I tried renaming the parent of my style theme. I tried using andrioud:background and background. The only thing that is changing is when I use another parent like
Theme.App.Compat.Light or Theme.AppCompat.Light.DarkActionBar.
Does someone have an idea, how I could be able to change the colors and other stuff, on runtime?
With new AppCompat-v7 (v21) you can use new color theming attributes. See here.
Or alternatively you have to use <item name="actionBarStyle"> property (without prefix android).
To use background color with AppCompat, you need to also define the item name without the android: attribute.
for example:
<style name="MyActionBar" parent="Theme.AppCompat.Light">
<item name="android:background">#color/action_bar_background</item>
<item name="background">#color/action_bar_background</item> //<--background item without the android attribute
</style>
and then in your custom theme do the same thing for the custom actionbar style:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
</style>

Android Border Less Button Pressed State Background Color

How can we change the background colour of a Border less button when the button is pressed.
I used this:
android:background="?android:attr/selectableItemBackground"
android:text="#string/btn_skip"
Where my button Displays a label "SKIP" as defined in my "strings.xml".
Now When I test this it is Good Except It shows default "Blue" Colour when in Pressed State.
I want it to match it with other elements of my My UI theme that are "Orange" "#FF8800"
Any Ideas?
Thankx in advance...!
instead of using ?android:attr/selectableItemBackground you can create a xml in drawable in folder with following content.
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/orange"/>
<item
android:state_enabled="false"
android:drawable="#color/default"/>
<item
android:drawable="#color/default"/>
</selector>
Updated:
so you save this files as : btn_drawable.xml in drawable folder.
Simply replace ?android:attr/selectableItemBackground
with *#drawable/btn_drawable.xml*
Thanks #Nimish-Choudhary ...! I followed your advice. and I have explained it further for clarity to all having same question as me as a beginner.
Create an xml with name say "btntransparent.xml"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="#color/pressed"/>
<item
android:state_enabled="false"
android:drawable="#color/defaultColor"/>
<item
android:drawable="#color/defaultColor"/>
</selector>
Next add the colors "pressed" and "defaultColor" to another xml say "colors.xml"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pressed">#CCFF8800</color>
<color name="defaultColor">#00000000</color>
</resources>
Here "#CCFF8800" is my pressed state Translucent Orange and "#00000000" is the 100% Transparent Black (;-) thats invisible). You can find more about color codes at Color| Android Developers
Now put the "colors.xml" in values Folder and "btntransparent.xml" in drawable Folder.
Now the last step is to voila use it in the button as
<Button
android:id="#+id/id_btn_skip"
android:background="#drawable/transparentbtn"
android:onClick="skipToMain"
android:text="#string/btn_skip" />
And thats should do the job...!
Take care.
regards,
raisedadead
If I understand you correctly, what you could do is add new resource in #drawable for example my_ripple.xml
<?xml version="0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF8800">
</ripple>
Then simply set this as your background.
In your theme add the following:
<item name="android:selectableItemBackground">#FF8800</item>
to override the default blue.

Resources