I want to draw text in Canvas. using this code:
canvas.drawText(getString(R.string.test1)+c, 30,320, paint);
a need change of "c" to bold...
Thanks...
the class Paint has method setTypeface , you can pass a Typeface.
code exmaple:
paint.setTypeface(Typeface.DEFAULT_BOLD);
so if you want change part of text, can draw one by one through change the typeface.
also, you can try use html code like <b>c</b>
Canvas.drawText and its various variants do all expect either a String, CharSequence or char[]. All those types do not support Spannable or Stylable objects. Short: It's not possible in the way you want.
You probably can try to implement the suggesstions idiottiger posted.
Related
I would like to add text like this, is this possible with MaterialLayout & MaterialTextInput ??
It can be done in two ways.
The more complicated way is to extend the MaterialTextInput and override methods.
The simple way is to put the MaterialTextInput in a FrameLayout along with a TextView with a fixed size. Create a same size dummy Drawable (eg: ColorDrawable) and set it as end drawable.
Comment for further information.
i want to set my textview's inputtypeto be asterisk or in bullet shape. i can set this property using XML file(layout). but when i want to set this programatically it does not work. I use textview1.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); but it show the string that i passed to it. Thanks.
Looking in the original documentation. You need two values since it manage bit definitions:
http://developer.android.com/intl/es/reference/android/text/InputType.html
textview1.setInputType(InputType.TYPE_CLASS_TEXT | InputType. TYPE_TEXT_VARIATION_PASSWORD);
I have problem on Android to do rainbow programmatic color on TextView.
Here specific condition of TextView:
String on TextView may contain character and number in unspecific order.
Example: AA11BB22, X2YY3ZZA1
For character (A-Z), I wish to display color BLUE.
For number (1-9), I wish to display color RED.
Example: AA11BB22 will display 'AA', 'BB' will display BLUE, and '11', '22' will display RED in TextView.
I know, there few solution to do solve using generate Image or HTML on canvas.
Is better or worse to do generate TextView for each chunk of part then color it?
Or maybe your guys has elegant solution for my situation.
Thanks.
You can make use of Spannable. This link will help you to understand how to use Spannable http://www.chrisumbel.com/article/android_textview_rich_text_spannablestring
You should have a look at Spannable string. http://developer.android.com/reference/android/text/SpannableString.html. The link provided by android.fryo is good and has a complete example.
I have an Edit text field and set his inputType to "textPassword".
The default view shows little dot icons. I would like to increase their size. I assume that there's no "largeTextPassword" option and you should set this up yourself.
I made a new large dot icon and would like to place it in instead of the regular one. Now I use the setText() method to insert the text into it. How do I combine between those values?
I'v tried to increase the textSize but the padding drove me crazy on different screen sizes.
I'v tried to use the setCompoundDrawablesWithIntrinsicBounds(R.drawable.dot, 0, 0, 0) method but still, I'm not sure this the right way.
If someone can shed some light on this would be great.
Don't use android:inputType="textPassword" because this will replace the characters with the default dot character.
Add a TextWatcher and, as the user types, store/append the new character in/to a String and replace that character in the EditText with an ImageSpan of your own.
I have TextView. Using java code I want to set color for string variable that I have to append to the text. Variable is generated at run time.
I explored Spannable but you have to give start and end which is not fixed.
Any other way to fix this. Please help.
Code:
String text; (Filled at runtime)
//but I want it to be different color
textview.append(text);
You can do something like this to set the text in your TextView:
tv1.setText(Html.fromHtml("<font color='red'>R</font><font color='green'>G</font><font color='blue'>B</font>"));
The issue with this is that when you have just one text object you can only have one colour for it. You will have to use more then one text object (each with different colours) and juxtapose them in you design.