LeadingMarginSpan bug in JP or KR Locale on OneUI

LeadingMarginSpan bug in JP or KR Locale on OneUI

When first system language list is Japanese or Korean,
or explicitly set the locale language to Japanese or Korean,
the follow code using LeadingMarginSpan leads the bug.
However, Chinese is ok. It is magical.

This issue can be 100% reproduced on any Samsung phone
using OneUI 1, 2 and 3 (refs to the Android 9, 10, and 11).
There is no such issue on pure AOSP (5~11).
or any other OEM bands StockROM like Sony, Xiaomi, etc.

  • Samsung A6s, Android 8.1, correct:
    A6s-8.1

  • Samsung Note 9, Android 10 with OneUI, incorrect:
    Note 9-10(OneUI)


The whole executable demo project git repository can be found here:

A demo apk here:


Core logic snippets:

  • MainActivity.java
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initKoreanLocale();

        setContentView(R.layout.activity_main);

        initView();
    }

    private void initKoreanLocale() {
        Locale locale = new Locale(Locale.KOREAN.getLanguage());
        Locale.setDefault(locale);
        Resources resources = getResources();
        Configuration config = resources.getConfiguration();
        config.setLocale(locale);
        resources.updateConfiguration(config, resources.getDisplayMetrics());
    }

    private void initView() {
        TextView tv = findViewById(R.id.tv);
        CharSequence text = tv.getText();
        SpannableString spannableString = new SpannableString(text);
        LeadingMarginSpan lms = new LeadingMarginSpan.Standard(100, 0);
        spannableString.setSpan(lms, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setText(spannableString);
    }
}
  • activity_main.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tv"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:background="#00AAFF"
    android:text="1111111111111111111111111111111111111111111111111111111111111111111" />

Hi @imknown ,

You may report the issue to the Samsung Developer Support team.

Azad

Hi, @azad, thanks for your reply. :grin:
Using that “Support Request” now. :+1: