how to align text width in a Textview? - android

I want to align text in My TextView like this
and my current appearance of textView is like
How can I achieve text layout without using Webview

TextView in Android O offers full justification (new typographic alignment) itself.
You just need to do this,
textView.setJustificationMode(JUSTIFICATION_MODE_INTER_WORD);
default is JUSTIFICATION_MODE_NONE

You can use:
https://github.com/bluejamesbond/TextJustify-Android
Install Just add to your build.gradle
dependencies {
compile 'com.github.bluejamesbond:textjustify-android:2.1.6'
}
or
use : https://github.com/Saleh-Hassan/RTL-TextJustify-Android
Example:

Related

Partly editing the text of a TextView

So, let's assume that I want to show a text such as : "Hello stranger ", using TextView. How would I do that? I realized that I cannot edit only a part of the text in TextView by changing textStyle attribute.
Use yourTextViewName.setText(Html.fromHtml(<b>Hello</b> <i>stranger</i>);
Reference here: https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String,%20int,%20android.text.Html.ImageGetter,%20android.text.Html.TagHandler)
Don't bother with complexity.
Place a TextView with the uneditable text on the left of the EditText. Change the margins and everything that makes it look like a unified view and you're done.
You can define the string in string.xml like this
<string name="text"><b>Hello</b><i>stranger</i></string>
and call it in your TextView like android:text="#string/text". It will work for you.

Why does AppCompatTextView showing wrong text in layout designer?

As you see in the picture there is text in the AppCompatTextView left design view.
To the right in setting pan I clearly set the text like:
android:text="some text"
Any ide?
You should TextView instead of AppCompatTextView.
From the documentation:
This will automatically be used when you use TextView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

How to add fixed text to left of AutoCompleteTextView?

I want to implement AutoCompleteTextView something like what Gmail app in Android does.
I am not sure how to set "To" fixed text on the left side of AutoCompleteTextView.
How is this implemented? Do I have to put TextView inside AutoCompleteTextView to show "To" label. If I do that my cursor starts from the beginning of AutoCompleteTextView and not after TextView.
How should I achieve this view
You can put a TextView to the left of the AutoCompleteTextView. Use a horizontal LinearLayout for that. You can set the border (the underline with the little ticks) on the linear layout if you want one.
My style of implementation of it is to use android:drawableLeft. Create a drawable(could be image) first which in your case "To". Then apply it in the xml declaration of your AutoCompleteTextView like this.
<AutoCompleteTextView
android:id="#+id/auto_complete_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/to_drawable_label"/>
I hope this helps. :)
you just need to create an adapter and set it to AutocomleteTextView.

Setting the text appearance of an android TextView in Java code

How can I set the text appearance of an android TextView to large in Java code? There is a method setTextAppearance(), but I don’t know how to use it.
Just try that:
textView.setTextAppearance(this, android.R.style.TextAppearance_Large);
Try this:
textView.setTextAppearance(android.R.style.TextAppearance_Large);

How to justify the description in single textview

In my application, I have an TextView with many lines beside of product, but I need the data with proper appearance.Is it possible to have justified alignment dynamically?
you can align your text dynamically some how as you want...
but, i guess there is no such facility available in android to fully justify text as the text editors does...
Use Html Formatting in your textView like
yourTextView.setText(Html.fromHtml("<h1>Product Name</h1><br><p>Content</p>"));
Yes you can get the instance of TextView on activity startup
TextView t = (TextView)FindViewById(R.id.TextView1)
t.setTextAppearance(context,parameter)

Categories

Resources