Android selector & text color
And selector is the answer here as well.
Search for bright_text_dark_focused.xml in the sources, add to your project under res/color directory and then refer from the TextView as
android:textColor="@color/bright_text_dark_focused"
Databinding selector in TextView textColor
Android Data Binding doesn't know about resource types, so you must supply it in the expression:
android:textColor="@{channel.unreadCount > 0 ? @colorStateList/selector_conversation_row_title_unread : @colorStateList/selector_conversation_row_title_read}"
Using selector to change TextView text color
You have to use getColorStateList(). And for xml, see here.
I was also struggling with this problem. If you want to have use a state list
, you need to declare it in the color
resources folder, instead of the drawable
folder, and use the setTextColor(getResources().getColorStateList(R.color.tab_text_selector))
method.
Android - Button's textColor with a selector not working
Try this one:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@android:color/black"/>
<item android:state_pressed="true" android:color="@android:color/black"/>
<item android:color="@android:color/white"/>
</selector>
How can I set the color and size of the text? (I use the selector)
This way is just for the background of the button.
You should use another selector on the android:textColor="@color/your_color_selector"
and put this file under the res/color folder
Here is an example:
your_color_selector.xml
<item android:state_pressed="true" android:color="@android:color/blue"/>
<item android:state_enabled="true" android:state_selected="true" android:color="@android:color/white"/>
<item android:color="@android:color/black"/>
Android Selectors Text Color
Why don't you just use one background xml? Like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@color/white"
android:textColor="@color/black" />
<item android:drawable="@color/black"
android:textColor="@color/white"/>
</selector>//Untested
And set it to be background for the button. If it doesn't work you can always do it programmatically. Hope this helps.
How about this:
button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN )
{
button.setBackground("#000");
edittext.setTextColor("#dedede");
return true;
}
else
{
button.setBackground("#dedede");
edittext.setTextColor("#000");
return true;
}
return false;
})); // Untested. Sorry i'm away from pc :(
Separate day/night selector for button text color
create folder drawable-night
at put night-variant in it (same file name), leave untouched file in common drawable
folder. this way you can also "overwrite" attributes like colors
, dimens
, even layout
best option would be to introduce DayNight
theme support, check out official doc, plenty of tutorials in search engines... (look for DayNight
theming)
Android customized button; changing text color
Create a stateful color for your button, just like you did for background, for example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Focused and not pressed -->
<item android:state_focused="true"
android:state_pressed="false"
android:color="#ffffff" />
<!-- Focused and pressed -->
<item android:state_focused="true"
android:state_pressed="true"
android:color="#000000" />
<!-- Unfocused and pressed -->
<item android:state_focused="false"
android:state_pressed="true"
android:color="#000000" />
<!-- Default color -->
<item android:color="#ffffff" />
</selector>
Place the xml in a file at res/drawable folder i.e. res/drawable/button_text_color.xml. Then just set the drawable as text color:
android:textColor="@drawable/button_text_color"
Related Topics
Google Map Signed API Key Errors in Android
Listadapter Not Updating Item in Recyclerview
Overlay Two Images in Android to Set an Imageview
Android: Getting a File Uri from a Content Uri
How to Programmatically Open the Permission Screen for a Specific App on Android 6.0 (Marshmallow)
How to Switch Activity Without Animation in Android
Difference Between Android.App.Fragment and Android.Support.V4.App.Fragment
How to Determine If a Firebase User Is Signed in Using Facebook Authentication
How to Deal with Install_Parse_Failed_Inconsistent_Certificates Without Uninstall
Pass a String from One Activity to Another Activity in Android
Where Is Android.Os.Systemproperties
Best Way to Work with Dates in Android SQLite
How to Open a Second Activity on Click of Button in Android App
Android Paint: .Measuretext() VS .Gettextbounds()
Replace Selector Images Programmatically
How to Build an APK File in Eclipse
How to Know an Application Is Installed from Google Play or Side-Load