android:textColor实际上没有工作

enter image description here

我的应用程序中有一个Edittext.我在XML中以下列方式将其认颜色设置为黑色:

android:textColor="@android:color/black"

布局:

<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中时,文本会粘贴到另一种颜色而不是黑色中.

无论我复制它的颜色如何,我如何将颜色标准化为黑色.

更新:

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),length,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                spannable.setSpan(new RelativeSizeSpan(5.0f),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 before,int count) {
            }
        });

解决方法

复制粘贴行为因供应商而异,具体取决于它们添加功能.

我的建议是,当EditText失去焦点时,将onFocuschangelistener设置为editText,再次覆盖textColor!这是一个简单的解决方法.试试让我知道.

更新:
由于你只有一个EditText字段,它永远不会失去焦点,上面的解决方案需要稍加调整.

在布局中,添加一个EditText字段.将其可见性设置为GONE.对于现有的EditText字段,添加android:imeOptions =“actionNext”.在您的活动中,对于新添加的’EditTextfield,将其输入类型设置为TYPE_NULL.现在,当用户在keyborad中按下下一个按钮时,yourEditText`将失去焦点,从而导致更改textColor.这是解决方法,而不是解决方案.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...