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));
Related
I want to make a TextView with a link. I made it with combination of html and bit of java:
// used to enable link navigation on TextView
setMovementMethod(LinkMovementMethod.getInstance())
// TextView with link
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:linksClickable="true"
android:text="#string/link"/>
// #string/link
<string name="link">Test link</string>
However there is still one issue, the space before actual link text is underlined like this:
Why is that and how could it be fixed?
// #string/link
<string name="link1">Test link</string>
You can use the white space in xml as string use . XML won't take white space as it is. it will trim the white space before setting it. So use instead of single white space.
Use CDATA in string to use HTML tags and use Html.fromHtml() method to set the text.
Implementation below:
Set the text using Html.fromHtml() in your Activity class.
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(Html.fromHtml(getString(R.string.link)));
textView.setMovementMethod(LinkMovementMethod.getInstance());
In strings.xml modify as below:
<string name="link">Test <![CDATA[link]]></string>
i am working on a android application in which text is entered by Button.Pressing that button will create a string and that string will be displayed on the textView, If the is Button is pressed again then the created string will be added to the string on textView ,in case the button is pressed many times, a long string is created which cant be shown in textview due to single line.only the beginning strings will be shown.so my question is how to make disappear old rather than disappearing of new text in single line textView???
i got the solution to some extent in which i am able to shift the older text with new text when it becomes big for screen.but how should i scroll back to that older text??
help me out guys
you can use android:ellipsize="start"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="start"
android:maxLines="1"
android:text="Hello World! This is a really long string on a single line meant to truncate in the beginning with an ellipse." />
This however, will not scroll.
After googling for hours....i came up with a result....
TextView mTextView;
Inside onCreate()
mTextViewT.setHorizontallyScrolling(true);
mTextViewT.setSingleLine(true);
mTextViewT.setInputType(InputType.TYPE_CLASS_NUMBER);
how can i get the exact value of the specific word in a textview when:
1 - the user had taped the word (the word can be just one of many in some text chunk),
2 - the textview has in its xml layout, android:textIsSelectable="true" ,
so by default android lets the user to highlight a specific word
and opens a small menu(copy, paste, share). can i manipulate this menu or maybe add more options to it in order to extend it and do something i want with the highlighted word?
i need to get the exact word based on some interaction with the user(click , tap, select....)
i didn't find any straight forward answer. is it even possible?
(i have android htc one x)
Thanks.
A more suitable component to use for your scenario is EditText.
It is declared like this in your manifest file:
<EditText
android:text=" This is not an editable EditText"
android:id="#+id/EditText01"
android:layout_width="wrap_content"
android:textColor = "#android:color/white"
android:editable = "false"
android:cursorVisible="false"
android:layout_height="wrap_content"
android:background = "#android:drawable/dark_header">
</EditText>
Then, it is only two lines of code to get the selected text:
EditText et = (EditText)findViewById(R.id.title);
String selectedText = et.getText().substring(et.getSelectionStart(), et.getSelectionEnd());
Here, we assumed that the text was selected from left to right. If it was selected from right to left, then above would result in an exception so you can avoid that by checking if start position is higher than the end position.
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");
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));