old theme in 4.0+ app - android

I've created a spinner in my activity and when i run my app on my Jelly Bean device the theme of the spinner is like 2.x, how can i get the ICS one?
Here's my spinner code :
<Spinner
android:id="#+id/spinnermap"
style="#android:style/Theme.Holo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
As you can see I tried to set the global style "Holo" but no results..
I had the same problem with a NumberPicker but can't remember how I fixed it.

style="#android:style/Theme.Holo"
This is not the solution. You won't have a fallback on pre HC devices.
You need to declare a Theme for your whole application if you want to use the holo theme in your whole app for HC+(I assume this is what you want to have).
In your Manifest:
android:theme="#style/MyTheme"
values/styles.xml:
<style name="MyTheme" parent="android:Theme.Light">
</style>
values-v11/styles.xml:
<style name="MyTheme" parent="android:Theme.Holo.Light">
</style>
Now you'll have a dropdown spinner on HC+(and also other holo widgets of course)
However if you just want to have the spinner to be "holofied" you can do this:
<Spinner
android:id="#+id/spinnermap"
style="#style/MySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
values/styles.xml:
<style name="MySpinner" parent="android:Widget.Spinner">
</style>
values-v11/styles.xml:
<style name="MySpinner" parent="android:Widget.Holo.Spinner">
</style>

Related

colorButtonNormal has no effect?

I am trying to apply a unified style on my button.
This is my v21/styles.xml
<style name="DefaultButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:colorButtonNormal">#f00</item>
<item name="android:textColor">#color/colorTextSecondary</item>
</style>
I apply this to my button like this
<Button
android:id="#+id/submit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="#dimen/unit_large"
style="#style/DefaultButton"
android:text="Lemme In!" />
nothing fancy going on in here. Yet the color of my button doesn't change. Did something change over the material support packages? I am using '25.3.1'
Actually all of this is part of a greater effort I have to do to change the default button style of the application like this
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">#style/DefaultButton</item>
</style>
I would then remove the individual styling attributes on all the buttons
Change this style="#style/DefaultButton" to
android:theme="#style/DefaultButton"

ImageButton background color with appcompat

I've got problems to have a good background from an AppCompatImageButton, just to try I'm comparing this two layouts:
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/imageButtonI"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="#string/icolor"
android:tint="#color/accent"
app:srcCompat="#drawable/magnify"/>
<ImageButton
android:id="#+id/imageButtonS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="#string/scolor"
android:tint="#color/accent"
android:src="#drawable/magnify"/>
and the style file:
<style name="AppBaseTheme" parent="android:Theme.Material">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primaryDark</item>
<item name="android:colorAccent">#color/accent</item>
</style>
As you can see from this image however, the background of ImageButton is "normal" while there isn't any background in the appcompat one. How can I have the "normal" background using AppCompatImageButton?
A good way to style the Button is to use the style #style/Widget.AppCompat.Button.Colored.
The Widget.AppCompat.Button.Colored style extends the Widget.AppCompat.Button style and applies automatically the accent color you selected in your app theme.
<Button
style="#style/Widget.AppCompat.Button.Colored"
/>
To customize the background color without changing the accent color in your main theme you can create a custom theme for your Button using the android:theme attribute and extending the ThemeOverlay theme.
<Button
style="#style/Widget.AppCompat.Button.Colored"
android:theme="#style/MyButtonTheme"/>
defining the following theme:
<!-- res/values/themes.xml -->
<style name="MyButtonTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="colorAccent">#color/my_color</item>
</style>
I am not sure which version of support library are you using, but before there was bug in the library which is reported here,
https://code.google.com/p/android/issues/detail?id=78428
But they have resolved it in the latest update,
Yes, it appears to work now with the introduction of
android.support.v7.widget.AppCompatButton in AppCompat v22.1.0, color
can be controlled at overall theme level with "colorButtonNormal".
http://android-developers.blogspot.com/2015/04/android-support-library-221.html
http://chris.banes.me/2015/04/22/support-libraries-v22-1-0/
for theme
<item name="colorButtonNormal">#color/button_color</item>
for version 21
<item name="android:colorButtonNormal">#color/button_color</item>
Hope this will help you.
Thanks

Android Button background color not changing

In this android project im creating a default button style.
my styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">#style/ButtonStlye123</item>
</style>
<style name="ButtonStlye123" parent="android:style/Widget.Button">
<item name="android:textSize">19dp</item>
<item name="android:layout_margin">8dp</item>
<item name="android:padding">8dp</item>
<item name="android:textColor">#color/ColorDivider</item>
<item name="android:background">#color/ColorAccent</item>
</style>
my button in a fragment.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnLogin"
android:id="#+id/btn_login"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:theme="#style/ButtonStlye123"
android:onClick="login" />
In the preview in android studio it looks exactly like I want, but when I run the app on my device the background color is gray ("default button color"). If i change the text color in my styles.xml like:
<item name="android:textColor">#color/ColorPrimary</item>
it changes (also on my device) so the custom style is loading, i tryd different colors (that worked for the text) for the button but it wont change.
Why isnt my background color loading?
Try use AppCompactButton
instead of
<Button
use
<androidx.appcompat.widget.AppCompatButton
that will do the trick
Update: 01/06/2021
Found out that the above will not work on earlier Android versions.
For materiel design Button use
app:backgroundTint="#color/green"
Please Use androidx.appcompat.widget.AppCompatButton instead of Button.
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/button_id_Login"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#id/textInnputLayout_editText_id_password"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/Login_screen_button_text"
android:background="#drawable/login_button_style"
android:textAllCaps="false">
</androidx.appcompat.widget.AppCompatButton>
You might be using targetSdkVersion 30 material theme
The solution is change theme.xml style
From
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
To
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
Replace with
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Changing MaterialComponents to AppCompat works for me..
I think you need to change your attribute from "theme" to "style". These files are intended for different things, so are used differently.
Style is used to assign attributes to individual views or components, and Theme is used to apply attributes to the entire app.
So try this instead:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnLogin"
android:id="#+id/btn_login"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
<!-- This attribute was changed -->
android:style="#style/ButtonStlye123"
android:onClick="login" />
You should also split these different types of XML into the correct files as appropriate (styles.xml and themes.xml - instead of keeping them all in the same file). This is convention, and won't effect the code compilation or execution, but is recommended as a code style.
Use this attribute backgroundTint it will help you. It work for me. Example :
android:backgroundTint="#color/md_orange_800"
if you are using Android Studio Version 4.1 and above (Beta)
check your themes.xml file in values.
<style name="Theme.NavaFlashLightV4" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
</style>
change the attribute to #null
<style name="Theme.NavaFlashLightV4" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#null</item> <!-- HERE -->
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
</style>
for other old versions of Android Studio
just change this attribute
<item name="colorPrimary">#color/colorPrimary</item>
to
<item name="colorPrimary">#color/#null</item>
finally set the background of the button to the drawable icon you want.
example:
<Button
android:id="#+id/btnSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/ic_launcher_background" /> <!--the drawable you want-->
You only need to change your App Theme from Theme.MaterialComponents.DayNight.DarkActionBar to Theme.AppCompat.Light.NoActionBar inside styles.xml file
example :
from : style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"
To : style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"
your style should be like this....
<style name="ButtonStlye123" >
<item name="android:textSize">19dp</item>
<item name="android:layout_margin">8dp</item>
<item name="android:padding">8dp</item>
<item name="android:textColor">#color/ColorDivider</item>
<item name="android:background">#color/ColorAccent</item>
</style>
and in layout
<Button
android:id="#+id/btn3"
style="#style/ButtonStlye123"
android:layout_width="#dimen/sixzero"
android:layout_height="#dimen/sixzero"
android:text="3" />
I am using targetSdk 30 and compileSdk 32 and I am using Button widget. Android Studio version 2021.1.1
In my case, following change worked,
In AndroidManifest.xml, under "application" tag changing "android:theme" from
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
to
android:theme="#style/Theme.MaterialComponents.DayNight.NoActionBar"
I moved to Theme.AppCompat.Light.NoActionBar to remove the title bar. At first I tried to change "style" to "Theme.AppCompat.Light.NoActionBar" inside themes.xml but it didn't work for me.

appcompat v22.1 widget tinting doesn't show pre 5.0

I'm using the AppCompat lib v22.1 to give some material design to multiple android versions. If I use the new widget tinting feature, it does not show up in Kitkat even with AppCompat.
in layout:
<Button
android:id="#+id/mybtn"
android:text="Test"
android:theme="#style/MyTheme.BlueButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
in theme xml:
<style name="MyTheme.BlueButton">
<item name="colorButtonNormal">#color/blue</item>
</style>
Is this something I'm doing wrong or a bug in AppCompat?
I was able to achieve desired results on Kitkat and Lollipop by using the following setup:
build.gradle (partial)
dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
}
values/styles.xml
<resources>
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="ThemeOverlay.AppTheme.Blue" parent="ThemeOverlay.AppCompat.Dark">
<!-- ThemeOverlay themes define only some attributes, those which make
backgrounds dark and highlights and texts light for ThemeOverlay.AppCompat.Dark
or the other way around for .Light. The rest is taken from the activity theme.
You only customize what you need - here the button color. -->
<item name="colorButtonNormal">#color/blue_500</item>
</style>
<style name="ThemeOverlay.AppTheme.Yellow" parent="ThemeOverlay.AppCompat.Light">
<!-- This worked correctly even with parent="Theme.AppTheme". -->
<item name="colorButtonNormal">#color/yellow_500</item>
</style>
</resources>
layout/activity_main.xml (partial)
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:theme="#style/ThemeOverlay.AppTheme.Blue"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:theme="#style/ThemeOverlay.AppTheme.Yellow"/>
EDIT: (oh yeah I forgot) MainActivity.java
public class MainActivity extends AppCompatActivity { ... }
Result
I found out why the original code didn't work when I thought it should. I was using FragmentActivity from support v4 lib, which doesn't seem to have the new v7 AppCompat features for themes built in. Changing my activity to AppCompatActivity makes the theming work with no changes from what I had.
A More technical explanation here: https://stackoverflow.com/a/29978777/3517023

How to override CheckBox color using AppCompat

When my checkbox is checked, I want the color to be #color/colorPrimaryLight. I can set it that way for Lollipop by setting
android:buttonTint="#color/colorPrimaryLight"
in the CheckBox but I don't know how to do it for anything before Lollipop without changing
<item name="colorControlActivated">#color/white</item>
in my theme.
CheckBox for Lollipop:
<CheckBox
android:buttonTint="#color/colorPrimaryLight"
android:id="#+id/SwapCheckbox"
android:layout_marginTop="#dimen/margin_top"
android:layout_marginLeft="#dimen/margin_left_right"
android:layout_marginRight="#dimen/margin_left_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
and for anything before Lollipop (and higher than 4.0.3):
<CheckBox
android:id="#+id/SwapCheckbox"
android:layout_marginTop="#dimen/margin_top"
android:layout_marginLeft="#dimen/margin_left_right"
android:layout_marginRight="#dimen/margin_left_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And I also have in the theme for my app:
<style name="AppTheme" parent="Theme.AppCompat.Light">
//...
<item name="colorControlActivated">#color/white</item>
//...
</style>
I can't change colorControlActivated as it must be white for the indicator in my ViewPager. Is there anyway to change the background color of my checkbox (even if it is to the default Holo style however best so that it is set to #color/colorPrimaryLight)?
Use the following property in the App compat theme like below
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorAccent">#color/colorAccent</item>
</style>
and use the android.support.v7.widget.AppCompatCheckBox instead of CheckBox

Categories

Resources