gpt4 book ai didi

java - Android:当父级聚焦时更改 TextView textColor

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:38 26 4
gpt4 key购买 nike

我在 LinearLayout 中有一个 TextViewLinearLayout 能够接收焦点,我希望 TextViewtextColor 在接收焦点时发生变化。我想使用 ColorStateList会工作,但是当 LinearLayout 获得焦点时,TextView 似乎没有获得焦点。我知道,因为我试过这段代码:

mTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
Log.d(TAG, "Changed TextView focus to: " + hasFocus);
}
});

并且没有任何记录。我不想在 LinearLayout 上使用 OnFocusChangeListener 来更改 TextViewtextColor,我认为这必须通过 XML 完成.这样做的原因是因为在另一个 Activity 中我有一个带有自定义适配器和自定义 View 的 ExpandableListView 并且 Android 更改了 TextViewtextColor当项目聚焦时,s(从亮到暗)在我的自定义 View 中。

最佳答案

这是一篇旧文章,但由于我遇到了同样的问题,这里是我找到的用于执行此操作的 XML 属性:

android:duplicateParentState="true"

(添加到 TextView 以在布局状态更改时更改其“聚焦”状态)

关于java - Android:当父级聚焦时更改 TextView textColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1582182/

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