so Im new to android and this is my problem :
-when I call style to a textview it doesn't change anything ,here is my style.xml :
<?xml version="1.0" encoding="utf-8"?>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- App branding color for the app bar -->
<item name="colorPrimary">#009688</item>
<!-- Darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#00796B</item>
<!-- Theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#536DFE</item>
</style>
<!-- Style for header text in the order form -->
<style name="HeaderTextStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">48dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textAllCaps">true</item>
<item name="android:textSize">15sp</item>
<item name="android:textColor">#FF5252</item>
</style>
and here is how I call the style
<TextView
android:hint="#string/topping"
style="#style/HeaderTextStyle"
/>
I tried to change just the color of the textview using
android:textColor="#FF5252"
but it did nothing
could someone help me , Ill be so greatful ,
Thanks in advance
You are setting textColor while you havent set text yet, you need to change textColo to textColorHint or change hint to text if you want to use textColor, for hint you use textColorHint and for text you use textColor like this.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text"
android:textColor="#color/colorPrimaryNero"
android:hint="some hint"
android:textColorHint="#color/colorPrimaryWhite" />
I am trying to create a custom rating bar where number of stars is dynamic and the drawable that I need to use also depends on the type, that I get from server.
I am doing this -
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:id="#+id/rating_bar_star"
android:layout_gravity="center"
style="#style/RatingBarStar"
android:stepSize="0.1"/>
then I added this in style -
<style name="RatingBarStar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_bar</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
this is my rating_bar.xml I added in drawable -
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background"
android:drawable="#drawable/rating_bar_empty" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/rating_bar_empty" />
<item android:id="#android:id/progress"
android:drawable="#drawable/rating_bar_filled" />
</layer-list>
rating_bar_empty.xml
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:drawable="#drawable/rating_off" />
and rating_bar_filled.xml -
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:drawable="#drawable/rating_on" />
and then added this in my java file -
rating_bar_star.setNumStars(getStars());
Obviously I am getting stars from server. Now my problem is when I click/select a star it doesn't select one whole star.
If number of star is 6 and I set stepSize as 0.8 then it works fine but same stepSize doesn't work for 10 stars. All I want, my stars to show selected appearance for selected stars.
this is what I get when I don't set stepSize and select/click on first star
and this when I click on second -
I have an android application, in it I have a list view with choice mode set to multiple. I have set the layout to simple_list_item_multiple_choice. It gives the checkboxes at the right side of the row.
But here's the problem: button tint of these checkboxes is terrible blue (which is far from my application color scheme). Whatever I do, I can't change it.
I have already tried: creating a style for CheckBox and creating a style for CheckedTextView, changing there all kinds of button tints and color accents.
None of it works.
What should I do?
A piece of layout:
...
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listView1"
android:layout_weight="1"
android:choiceMode="singleChoice" /> ...
A piece of activity code:
ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(),
android.R.layout.simple_list_item_multiple_choice, players);
itemsList.setAdapter(adapter);
Solutions I've tried:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:colorPrimary">#color/MainColor</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:textColor">#color/MainColor</item>
<item name="colorAccent">#color/MainColor</item>
<item name="colorPrimary">#color/MainColor</item>
<item name="android:checkboxStyle">#style/CheckBoxStyle</item>
<item name="android:checkedTextViewStyle">#style/CheckedTextViewStyle</item>
</style>
<style name="CheckBoxStyle" parent="AppTheme">
<item name="android:tint">#color/colorAccent</item>
<item name="android:buttonTint">#color/colorAccent</item>
</style>
<style name="CheckedTextViewStyle" parent="AppTheme">
<item name="android:colorButtonNormal">#color/colorAccent</item>
<item name="android:checkMarkTint">#color/colorAccent</item>
<item name="android:tint">#color/colorAccent</item>
<item name="android:buttonTint">#color/colorAccent</item>
<item name="android:colorAccent">#color/colorAccent</item>
</style>
UPD: Also, if someone knows how to implement this without checkboxes, but also without creating a useless custom adapter, I would accept this as an answer, too.
Beginning with Android Lollipop (Api 21) you can set checkMarkTint to your activity's theme:
<item name="android:checkMarkTint">#ff0000</item>
To control the checkMark's color.
If you only want to do this for this specific adapter, then create a new theme, extending your activity's theme:
<style name="AdapterTheme" parent="#style/MainTheme">
<item name="android:checkMarkTint">#ff0000</item>
</style>
And set it to your ArrayAdapter:
ContextThemeWrapper themedContext = new ContextThemeWrapper(this, R.style.AdapterTheme);
ArrayAdapter<String> adapter = new ArrayAdapter<>(themedContext, android.R.layout.simple_list_item_multiple_choice, players);
Create three drawables:
checkbox_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/btn_check_on" android:state_checked="true" />
<item android:drawable="#drawable/btn_check_off" android:state_checked="false" />
</selector>
btn_check_on.xml
<vector android:height="32dp" android:viewportHeight="105.0"
android:viewportWidth="105.0" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#color/colorAccent" android:pathData="M48,17c-17.12,0 -31,13.88 -31,31s13.88,31 31,31S79,65.12 79,48S65.12,17 48,17zM43.74,59.84L32.31,48.55l3.23,-3.19l8.2,8.1l17.34,-17.13l3.23,3.19L43.74,59.84z"/>
</vector>
btn_check_off.xml
<vector android:height="32dp" android:viewportHeight="105.0"
android:viewportWidth="105.0" android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#fafafa" android:pathData="M48,17c-17.12,0 -31,13.88 -31,31s13.88,31 31,31S79,65.12 79,48S65.12,17 48,17zM48,75.55c-15.21,0 -27.55,-12.33 -27.55,-27.55c0,-15.21 12.33,-27.55 27.55,-27.55c15.21,0 27.55,12.33 27.55,27.55C75.55,63.21 63.21,75.55 48,75.55z"/>
</vector>
Apply checkbox_selector.xml as drawable to your checkbox. You will get the desired result
I have this Theme,
<style name="AppTheme" parent="#style/AppBaseTheme">
<item name="android:buttonStyle">#style/MyButtonStyle</item>
</style>
I need to define another style for a button (called MyButtonStyleDealer).
Using the following code I get error android:buttonStyle has been already defined.
<style name="AppTheme" parent="#style/AppBaseTheme">
<item name="android:buttonStyle">#style/MyButtonStyle</item>
<item name="android:buttonStyle">#style/MyButtonStyleDealer</item>
</style>
I would like to know if it possible define a second style for the button and how to apply it to the View.
If got your question correctly, you can add inside your style file another entry for the button
<style name="MyNotClickableButtonStyle">
<item name="android:background">#drawable/my_button_background</item>
<item name="android:clickable">false</item>
</style>
and inside your layout,
<Button
style="#style/MyNotClickableButtonStyle"
You only can define one android:buttonStyle. If you want to change only this the button style has to add another style.
Another properties can be used if you want but only once.
For instance:
<style name="GlobalAppTheme" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:editTextStyle">#style/GlobalTextView</item>
<item name="android:textColor">#color/text_gray</item>
<item name="android:checkboxStyle">#style/CheckBox</item>
<item name="android:radioButtonStyle">#style/RadioButton</item>
<item name="android:buttonStyle">#style/Button</item>
<item name="android:textSize">14sp</item>
<item name="android:actionBarItemBackground">#android:color/transparent</item>
<item name="actionBarItemBackground">#android:color/transparent</item>
<item name="android:alertDialogStyle">#style/Theme.Sherlock.Light.Dialog</item>
</style>
<style name="GlobalAppTheme2" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:editTextStyle">#style/GlobalTextView</item>
<item name="android:textColor">#color/text_gray</item>
<item name="android:checkboxStyle">#style/CheckBox</item>
<item name="android:radioButtonStyle">#style/RadioButton</item>
<item name="android:buttonStyle">#style/Button</item>
<item name="android:textSize">14sp</item>
<item name="android:actionBarItemBackground">#android:color/transparent</item>
<item name="actionBarItemBackground">#android:color/transparent</item>
<item name="android:alertDialogStyle">#style/Theme.Sherlock.Light.Dialog</item>
</style>
You can set sepecific styles like this:
<Button
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage"
style="?android:attr/MyButtonStyleDealer" />
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" />