Justify align text in static layout? - android

How do I JUSTIFY align text in a static layout programmatically? Thanks for your time.
I only see the following options for staticLayout.setAlignment():
Layout.Alignment.ALIGN_CENTER
Layout.Alignment.ALIGN_NORMAL
Layout.Alignment.ALIGN_OPPOSITE

You can set it like textView.justificationMode = JUSTIFICATION_MODE_INTER_WORD. But it requires Android O (Api level 26).
source: https://stackoverflow.com/a/42991773/19115089
Another option would be to try a third party library like https://github.com/mathew-kurian/TextJustify-Android (but no longer maintained)

Related

Change Android CheckBox box's color programmatically (support library)?

I'm trying to change the checkbox box's color programmatically to a different color than the theme's default. The problem is I was doing something like this:
checkbox.setSupportButtonTintList(ColorStateList);
It works but it seems, according its class documentation, this method has been restricted to be used only by classes from the same package (com.android.support). This is the warning I got from Android Studio:
AppCompatCheckBox.setSupportButtonTintList can only be called from within the same library group (groupId=com.android.support)
Is there a standard/correct way of doing this for all API levels?
Finally, found the answer here from one of the Google guys: https://code.google.com/p/android/issues/detail?id=202235. I was right about not using:
checkbox.setSupportButtonTintList(ColorStateList);
It seems is a private API. Instead, you have to use:
CompoundButtonCompat.setButtonTintList(checkbox, colorStateList);
Based on rylexr answer, you can specify the color in the following way:
CompoundButtonCompat.setButtonTintList(checkboxView, ColorStateList
.valueOf(getResources().getColor(R.color.red)));
chxAll.setButtonTintList(ColorStateList.valueOf(Color.parseColor("#CC0000")));
chxAll is a object of android.widget.CheckBox
replace the hexacolor code for desigred color

Is there any alternatives of letterSpacing attribute for EditText in API level 20 or below

I've added Why my question is not duplicate of this question in Edit Section, Please review..
We use letterSpacing attribute in EditText to define the spacing between letters like .
But as per documentation, This was only introduced in API level 21 or above, If we try to use it in lower API level version, It shows rendering problem directly as in this picture.
Is there any alternatives for letterSpacing to use in EditText before API level 20 ?
Edit
It was marked as duplicate question but what I want to notify is android:textScaleX attribute and android:letterSpacing attribute is different.
Let's take an example by adding these two attributes in EditText
The result of adding android:letterSpacing is
And the result of adding android:textScaleX is
Sorry you couldn't adjust letterSpacing in Api before 21 but you can adjust it if you draw text on Canvas using 2D graphics APIs.

Android Studio Right to Left ListView

I've been trying to make a ListView to work as RTL (Right to Left).
I've added the following line in the ListView and LinearLayout properties:
android:layoutDirection="rtl"
and it still shows the list from left to right.
Any ideas?
Thank you all but I solved it with:
android:textDirection="rtl"
I've added it to the ListView and the layouts, and it worked. Next time you should try considering using this too for RTL layouts.
To take advantage of RTL layout mirroring, simply make the following changes to your app:
Declare in your app manifest that your app supports RTL mirroring.
Specifically, add android:supportsRtl="true" to the <application> element in your manifest file.
Change all of your app's left/right layout properties to new start/end equivalents.
If you are targeting your app to Android 4.2 (the app's
targetSdkVersion or minSdkVersion is 17 or higher), then you should
use start and end instead of left and right. For example,
android:paddingLeft should become android:paddingStart.
If you want your app to work with versions earlier than Android 4.2
(the app's targetSdkVersion or minSdkVersion is 16 or less), then you
should add start and end in addition to left and right. For
example, you’d use both android:paddingLeft and android:paddingStart.
RTL layout support feature is supported on Android 4.2(API level 17) or above only . Please Add android:layout_gravity="left/right" in your parent Layout . And also allow android:textAlignment.
Set minSdkVersion=17
Please read http://developer.android.com/reference/android/view/View.html#attr_android:layoutDirection
This will automatically adjust according to the device locale
android:textDirection="locale"

Implementing (switch\toggle button) depending on API level

My application will run on api level 9 devices or higher. Now i have a toggle_button on one of the layouts. I want to change this toggle button to switcher if the device is apilevel 14 or higher. How can i implement this? Sorry for my english.
If you are creating the content/pages in xml, simply copy your xml with same name but to the layout-v14 folder. Then change ToggleButton to SwitchButton, and Android will take care of rest :)
If you are coding it in jave, use:
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH){
//Add Switch
}else{
//add toggle
}
And when you'll want to use both (when using defining in xml) with the same java code use:
CompoundButton bt_toggle= (CompoundButton) findViewById(R.id.some_button);
bt_toggle.setChecked(false);
I have found a solution! link
It just adds a support library. And you can use switchers from api-level7!

android - how can i use the “android:layoutDirection”? - again

can someone help me how can i use this attribute android:layoutDirection ,
and please don't refer me to this question What is the status of Right To Left languages on Android? because it doesn't answer my question!
layoutDirection is not be published in 4.0,so you cannot use the attr,but if you not be using sdk,but build with all code of android.
first get the Linearlayout in your code when it created,normally after setContent,and using #hide api setLayoutDiredtion(View.LAYOUT_DIRECTION_LOCALE),which define in View.java
,of course,after 4.2 you can use layoutDirection in xml directly

Categories

Resources