微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.这是解决方法,而不是解决方案.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐