I have an Edittext in my application. I have set it's default color to black in the following manner in the XML:
android:textColor="@android:color/black"
LAYOUT:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context="scientificcalculatorapp.scientificcalculator.ScientificCalculator"
android:weightSum="1"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/transparent"
android:focusable="true"
android:focusableInTouchMode="true">
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/Output"
android:enabled="true"
android:focusable="true"
android:longClickable="true"
android:inputType="text"
android:textIsSelectable="true"
android:cursorVisible="true"
android:textColor="@android:color/black"
android:bufferType="spannable"
android:background="@android:color/darker_gray"
android:allowUndo="true" />
</LinearLayout>
当我从键盘获取输入时,这是有效的,但是当我从不同的应用程序复制不同颜色的内容,然后将其粘贴到此 EditText 中时,文本会粘贴为其他颜色而不是黑色。
无论我复制的是什么颜色,如何将颜色标准化为黑色。
UPDATE:
output.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
String yourCopiedString=output.getText().toString();
int length = yourCopiedString.length();
Spannable spannable= new SpannableString(yourCopiedString);
//set color
//set size
spannable.setSpan(new ForegroundColorSpan(Color.BLACK), 0,length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new RelativeSizeSpan(5.0f), 0,length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
output.setText(spannable);
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});