- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图做到这一点,当用户关注 TextView 时,背景会改变颜色,然后当它失去焦点时,textview 会失去焦点颜色。你能帮忙吗?
TextView tv1=new TextView(this);
tv1.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
v.setBackgroundColor(Color.RED);
}else{
v.setBackgroundColor(Color.TRANSPARENT);
}
}
});
最佳答案
默认textView是不可点击和不可聚焦的,那么你需要设置它。
试试这个。
tv1.setClickable(true);
tv1.setFocusableInTouchMode(true);
关于java - setOnFocusChangeListener 改变背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21848475/
我试图做到这一点,当用户关注 TextView 时,背景会改变颜色,然后当它失去焦点时,textview 会失去焦点颜色。你能帮忙吗? TextView tv1=new TextView(this);
我有一个 EditText ,提示“最多 20 个字符”,当我单击它时,它会消失,并带有 setOnClickListener 和 setHint在里面。但现在我想重新添加提示,如果这个人没有在上面添
我有以下自定义基础适配器。我有一个 ListView ,每个项目都有一个编辑文本。我想在用户离开 edittext 后立即保存该数据,但现在发生的情况是每次用户输入 1 个字符时,setOnFocus
android SearchView 有两个方法:setOnQueryTextFocusChangeListener 和setOnFocusChangeListener。它们可以互换吗?它们有什么区别
我正在使用这段代码来检查我的 edittext 焦点与否: gelar_pp=(EditText)polis.findViewById(R.id.gelar_pp); gelar_pp.se
尝试使用 setOnFocusChangeListener mMessageBox.setOnFocusChangeListener(new OnFocusChangeListener() {
来自引用文档, SearchView.setOnQueryTextFocusChangeListener - 设置一个监听器以在查询文本字段的焦点发生变化时发出通知。 和 View.setOnFocu
当我尝试以编程方式添加 TextView 时,我无法设置 setOnFocusChangeListener 甚至 setOnClickListener。 我试过了 txt1.requestFocus(
我有几个 EditText 字段,我想使用 setOnFocusChangeListener 将它们保存到 SQLiteDatabase。我是否必须为每个单独设置一个 onFocusChangeLis
我在 RecyclerView 的适配器类中的 onBindViewHolder() 上有以下内容: holder.answerEditText.setOnFocusChangeListener(ne
我是一名优秀的程序员,十分优秀!