替换costomized TextView中的文本

时间:2015-12-21 16:36:33

标签: android textview left-to-right

我正在尝试替换自定义文本视图中的文本。目的是强制文本为LTR;为了做到这一点,我在我的文本中添加了“\ u200E”前缀。 现在,setText()不会对自定义textView产生任何影响。

public class LocalizedTextView extends TextView {
    public LocalizedTextView(Context context) {
        super(context);
        init(context);
    }

    public LocalizedTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public LocalizedTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        this.setText("\u200E" + getText().toString());
    }
}

这是自定义元素:

<com.tempProject.customviews.LocalizedTextView
    android:id="@+id/item_text"
    style="@style/DrawerSectionText"
    android:textDirection="ltr" />

任何想要强制textView与RTL内容在4.2.0之前的设备左侧对齐的任何想法都将受到欢迎。 必须在清单中将android:supportsRtl标志设置为true。

0 个答案:

没有答案