Change Google Place Picker Appbar Text Color - java

I would really like to know if I am able to change the text color of the Appbar text in the PlacePicker API for Android. It should inherit the styling from my application, but it does not do that.
my styles.xml is as follows:
<style name="MaterialParent" parent="Theme.AppCompat.Light.NoActionBar">
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="icon">#color/icons</item>
<item name="divider">#color/divider</item>
<item name="colorControlHighlight">#color/accent_alpha26</item>
</style>
<style name="Material" parent="MaterialParent"/>
I've already tried changing android:textColorPrimary, android:textColorSecondary and textColor to white with no luck.

Please use Theme.AppCompat.Light.NoActionBar instade of Theme.AppCompat.Light.DarkActionBar

Just change the colorPrimary value of color file with the color hex code, that you want and it works fine.

Related

How to remove extra white background in buttons after using AppCompat Theme?

TL;DR;
How to remove the below unwanted white area?
I tried to change my theme which extends "Theme.AppCompat.Light.NoActionBar" and added my own customization.
After using the theme, all "pop-up" buttons have an extra white background like above screenshot:
How to remove those extra white area?
What xml attributes are controlling this?
styles.xml
<style name="MyCustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="android:alertDialogTheme">#style/CustomAppCompatAlertDialogStyle</item>
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
</style>

android:headerBackground having no effect

I'm currently working on creating a custom theme for a datePicker and I'm having some difficulty with setting the headerBackground and the circle around the selected date separately. I've set my theme up like this:
<style name="State0DatePickerTheme" parent="AppTheme">
<item name="colorAccent">#color/state0Dark</item>
<item name="android:headerBackground">#color/state0Primary</item>
</style>
App theme looks like this:
<style name="AppTheme" parent="State0BaseTheme">
<item name="colorPrimary">#color/state0Primary</item>
<item name="colorPrimaryDark">#color/state0Dark</item>
<item name="android:statusBarColor">#color/state0Primary</item>
<item name="android:colorControlNormal">#color/colorAccent</item>
<item name="android:background">#color/state0Primary</item>
<item name="android:textColorPrimary">#color/colorAccent</item>
</style>
And last but not least, State0BaseTheme looks like this:
<style name="State0BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/state0Primary</item>
<item name="colorPrimaryDark">#color/state0Dark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/state0Primary</item>
<item name="android:colorControlNormal">#color/colorAccent</item>
<item name="android:background">#color/state0Primary</item>
<item name="android:textColorPrimary">#color/colorAccent</item>
</style>
I had thought that overriding colorAccent, and setting headerBackground would work just fine, but I guess not? Here's what it looks like with all these styles:
If I set android:headerBackground in the xml of the datePicker, everything works great. However, I want to be able to change the theme for all screens of the app based on user input. Thoughts as to why this isn't working?
I read the link posted by #DasserBasyouni and found that making the parent of my datePickerTheme #android:style/Widget.Material.Light.DatePicker and setting android:datePickerStyle to #style/State0DatePickerTheme in State0BaseTheme worked perfectly

ImageButtons aren't taking attributes from theme styles

My ImageButtons don't seem to be affected by the parameters set out in the style document, however other Buttons are when I define their style in the exact same way.
This is a condensed version of my styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:buttonStyle">#style/Button</item>
<item name="android:imageButtonStyle">#style/ImageButton</item>
</style>
<style name="Button" parent="#android:style/Widget.Button">
<item name="android:background">#color/icons</item>
</style>
<style name="ImageButton" parent="#android:style/Widget.ImageButton">
<item name="android:background">#color/icons</item>
</style>
When using these styles (I've tried it with other items however none seem to work), normal Buttons will take the color of #color/icons, however ImageButtons don't. They also remain unaffected when their styles are set individually with style="#style/ImageButton", however if I set the background directly with android:background="#color/icons" on each button it does have an affect.
Use
style="#style/ImageButton"
in your button body like:`
<Button
style="#style/button_theme"
android:text="Sign In"
android:id="#+id/id" />`
this is the button style
<style name="button_theme">
<item name="android:background">#drawable/button_shape</item>
<!--<item name="android:padding">5dp</item>-->
<item name="android:textColor">#ffffff</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
OR you can use these styles in your theme like you shown above
just add this line
:-
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:buttonStyle">#style/Button</item>
<item name="buttonStyle">#style/Button</item>
<item name="android:imageButtonStyle">#style/ImageButton</item>
</style>
<style name="Button" parent="#android:style/Widget.Button">
<item name="android:background">#color/icons</item>
</style>
<style name="ImageButton" parent="#android:style/Widget.ImageButton">
<item name="android:background">#color/icons</item>
</style>

How to make alert dialog match theme color?

So in the app I am making, I have both a dark and light theme. The light theme works fine, but the alert dialogs I have still show the background the same as the light theme. Since it is dark, the text changes to light and the user can't see anything. Is there a certain attribute I need to change?
Here is the styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#E53935</item>
<item name="colorPrimaryDark">#C62828</item>
<item name="android:navigationBarColor">#E53935</item>
<item name="android:colorAccent">#1565C0</item>
<item name="android:colorForeground">#color/foreground_material_light</item>
<item name="android:colorBackground">#color/background_material_light</item>
<!-- Other attributes -->
</style>
<style name="Dark" parent="#style/AppTheme" >
<item name="android:colorForeground">#color/foreground_material_dark</item>
<item name="android:colorPrimary">#color/primary_material_dark</item>
<item name="android:colorPrimaryDark">#color/primary_dark_material_dark</item>
<item name="android:colorAccent">#color/accent_material_dark</item>
<item name="android:navigationBarColor">#color/primary_material_dark</item>
<item name="android:colorBackground">#color/background_material_dark</item>
<item name="android:textColorPrimary">#android:color/primary_text_dark</item>
<item name="android:textColorPrimaryInverse">#android:color/primary_text_light</item>
<item name="android:textColorSecondary">#android:color/secondary_text_dark</item>
<item name="android:textColorSecondaryInverse">#android:color/secondary_text_light</item>
<item name="android:textColorTertiary">#android:color/tertiary_text_dark</item>
</style>
Here is what it shows up as:
Solved: You need to create your own xml like this:
<item name="alertDialogTheme">#style/DarkAlertDialog</item>
With this being your custom dialog:
<style name="DarkAlertDialog" parent="Theme.AppCompat.Dialog">
<item name="background">#color/background_material_dark</item>
</style>
Use the parent AppCompat and then use colorPrimary and colorAccent properties (without an Android prefix) to theme things.
Right now the styles are coming from a dialog subtheme and not being affected by these style definitions.

Changing style works only partially: text color changes, background doesn't

I'm trying to change the style of a Button when someone clicks on it. I want to change both the background as the text colour. However, only the text color is changed. From that I conclude that the style is changed, but for some reason the background can't be overwritten.
I'm using this code in the onClick handler:
Button send_button = (Button) findViewById(R.id.button1);
send_button.setTextAppearance(context, R.style.activeButtonTheme);
The relevant styles in my styles.xml are:
<style name="buttonTheme">
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/orange</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="android:layout_margin">2dp</item>
</style>
<style name="activeButtonTheme" parent="#style/buttonTheme">
<item name="android:background">#color/orange</item>
<item name="android:textColor">#color/white</item>
</style>
What's the problem here?
I do not want to set the background color from Java, I only want to change the style in Java.
Use selector for that purpose. Check this link for details(Custom background section) Regarding to your code, define appropriate selector.xml file in your resources directory, something like that:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drawable_for_dissabled_button" android:state_enabled="false"/>
<item android:drawable="#drawable/drawable_for_pressed_button" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="#drawable/drawable_for_enabled_button" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="#drawable/drawable_for_enabled_button" android:state_enabled="true"/>
</selector>
Assign just created selector to the button in the layout file:
<Button android:id="#+id/your_button_id"
android:background="#drawable/selector" />

Categories