gpt4 book ai didi

android:textColor 实际上没有工作

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:42 26 4
gpt4 key购买 nike

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), 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) {
}
});

最佳答案

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

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

更新:
由于您只有一个 EditText 字段,因此它永远不会失去焦点,并且需要对上述解决方案进行一些微调。

在布局中,添加另一个 EditText 字段。将它的可见性设置为 GONE。对于现有的 EditText 字段,添加 android:imeOptions="actionNext"
在您的 Activity 中,对于新添加的 'EditText 字段,将其输入类型设置为 TYPE_NULL。现在,当用户按下键盘中的next按钮时,您的EditText` 将失去焦点,从而导致更改 textColor。这是变通办法,不是解决方案。

关于android:textColor 实际上没有工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41031206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com