What is the best way to justify TextView in Kotlin? - android

What is the best way to justify TextView (with LTR and RTL) in Kotlin?
I tried many libraries like:
implementation 'com.codesgood:justifiedtextview:1.1.0'
implementation 'me.biubiubiu.justifytext:library:1.1'
implementation 'com.github.bluejamesbond:textjustify-android:2.1.6'
implementation 'com.github.pouriaHemmati:JustifiedTextView:1.0.0'
But they are not a perfect solution.

In Kotlin, the best way to justify text in a TextView would be to use the gravity property in conjunction with the textAlignment property.
val textView = findViewById<TextView>(R.id.text_view)
textView.gravity = Gravity.END
textView.textAlignment = View.TEXT_ALIGNMENT_VIEW_END

Related

Combining maxLength with wrap_content on Android TextView

I have a needs to limit the length of a textview to a certain number and then make the text wrap. Unfortunately using maxLength will only "crop" the text and won't make it wrapping like it should be even when using android:layout_width="wrap_content". How to achieve this feature?
Add this to your text view,
android:layout_width="wrap_content"
And add this,
android:minEms="..."
Or
android:minWidth="..."

how to align text width in a Textview?

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:

How to create a view with design like datetimepicker (>4.0)in android

I need to create a view with design like DateTimepicker in Android
Something like:
Text1
Text2
Text3
How can I achieve this?
thanks
I think you have to use a Custom ScrollView. Or maybe use directly NumberPicker ?

Is there any way to use fontFamily on 4.0 devices?

android:fontFamily was applied for devices > than 16. That means 4.1 have this attribute but doesn't 4.0.4 for example.
So I'm trying to use
android:fontFamily="sans-serif-light"
To get a holo font. It works cool in 4.2 but not on 4.0.4, it's showing some default font.
Is there anyway to set it by xml? Or do I've to set it by code?
The easiest way is doing it on your code! Place the font in your assets folder, create and set it on your text view:
TextView text = (TextView) findViewById(R.id.textview03);
Typeface tf = Typeface.createFromAsset(getAssets(), "Molot.otf");
text.setTypeface(tf);
It is possible to do it on the xml. It's a lot harder thought. You have to extend the TextView component and use it on your xml instead of the typical android TextView.
Take a look on this answer for more details on how to achieve that.

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