Android:在关注父级时更改TextView textColor

Fel*_*lix 7 java android themes focus

我有一个TextView内部LinearLayout.在LinearLayout能够接收焦点,我想textColor的TextView,当它改变.我认为使用ColorStateList会起作用,但看起来TextView它没有得到焦点LinearLayout.我知道,因为我尝试过这段代码:

mTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

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

没有任何记录.我不想OnFocusChangeListener在LinearLayout上使用一个来改变textColor它TextView,我想这必须从XML完成.原因是因为在另一个活动中,我有ExpandableListView一个自定义适配器和自定义视图,当项目聚焦时,Android会在我的自定义视图中更改s(从亮到暗)textColor的TextViews.

小智 11

这是一个旧帖子,但由于我遇到了同样的问题,这里是我发现的XML属性:

android:duplicateParentState="true"
Run Code Online (Sandbox Code Playgroud)

(当布局状态发生变化时,添加到TextView以更改其"聚焦"状态)