Text in the textView seems like it is grayed out.
I want so set the text color as when you click textView then It seems in black color as it is enabled.
For changing the text color of TextView you need to set its textColor property.
In XML file you can do like :
<TextView
android:text="Some text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffff00"
android:background="#ff0000"
/>
Programatically you can set TextColor and its Background in TextView using :
text_view.setBackgroundColor(Color.RED);
text_view.setTextColor(Color.BLUE);
Hope this helps. !
try this code
text.setBackgroundColor(56565);
text.setEnabled(true);
it will helpful for u
you can change just alpha value of the textview like as following
from https://gist.github.com/Skamp/1330169
final ColorStateList colors = textview.getTextColors();
...
textview.setTextColor(colors.withAlpha(255));
Related
I want to make text inside Button partially bold but this doesn't work.
I have my text placed in string values. String styling is completely ignored and text appeared as "normal" style inside button.
<string name="gps_yes_button_text"><b>Yes, </b>confirm this location!</string>
Button:
<Button
android:id="#+id/gps_confirm_button"
android:layout_width="#dimen/gps_button_width"
android:layout_height="#dimen/gps_button_height"
android:layout_gravity="center"
android:elevation="#dimen/gps_button_elevation"
android:text="#string/gps_yes_button_text"
android:textColor="#color/colorText"
android:textSize="#dimen/gps_text_large"
android:textAllCaps="false"
android:background="#drawable/gps_rounded_button"/>
Please try to set the button text by coding as below.
String buttonText = "<b>Yes, </b>confirm this location!";
button.setText(Html.fromHtml(buttonText));
How do I change button background and text color in Android?
Unable to use Attributes of android.
Other than in XML you can also set color in class editor file like:
TextView.setColorFilter(Color.parseColor("#hexadecimal value"));
for Button:
Button.setBackgroundColor(Color.parseColor(“Hexadecimal value”));
In XML:
android:background="#color/colorAccent"
android:textColor="#color/colorPrimary"
Programmatically:
button.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
button.setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
I would like to set a red colour text in my app, but I don't know how.
Please provide references. Thanks.
If you want it to set in XML layout then use:
<TextView
...
...
android:textColor="#FF0000" >
</TextView>
If you want to set programmatically then use:
textview.setTextColor(Color.RED);
//textview must be defined in your class
Read the docs for TextView, specifically for textColor.
Use the following in your xml where you want to change the color to red and by using the other hexacode of color you can change to any other color. This is an example to set the color to red:
android:textColor="#FF0000"
Use this in your layout:
<TextView>
....
textColor="red"
....
</TextView>
Create a custom style resource which uses an Android Theme as a parent then override the text colors as defined in the Android theme.xml. Reference this new style in your AndroidManifest.xml's application tag.
I have the following TextView:
<TextView android:id="#+id/theFooBar"
android:autoLink="web"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="#string/fooBar"
android:textColor="#android:color/black"
android:textSize="20sp"/>
And the string:
<string name="fooBar">Foo <u>bar</u>.</string>
This gives my black, underlined text. What if I want blue, non-underlined text for the link (the "bar" part), but I want the rest (the "foo" part) to be black? How could I achieve that?
Add android:textColorLink in TextView to define text color for links
I recommended you to use WebView instead of TextView in this situation:
WebView web = (WebView) findViewById(R.id.theFooBar);
String str = "<font color='blue'>bar</font><font color='black'><u>foo</u></font>";
web.setBackgroundColor(0);
// It will sets the background color from white to transparent.
web.loadData(str, "text/html", "utf8");
I don't see any method like setStyle for class RatingBar. How can I set the rating style from code?
This works for me (source):
RatingBar rating =
new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
You need to set it in xml file! If you like to change it on the run, you can have two different View-s (rb) and switch them in the program (add/remove from layout) or use rb1.setVisibility(View.VISIBLE) and rb2.setVisibility(View.GONE);
<RatingBar
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentRight="true" android:id="#+id/rb1"
style="?android:attr/ratingBarStyleSmall"
android:clickable="false" android:numStars="5">
</RatingBar>
If you are programmatically creating the RatingBar as follows the
RatingBar rating = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall);
then don't for get to add
rating.setIsIndicator(false);
else the touch will not work on RatingBar.
The android.R.attr.ratingBarStyleSmall gives you very small stars if you want to have a slightly bigger stars use android.R.attr.ratingBarStyleIndicator