如何解决在自定义LinearLayout中可绘制的选择器
设置可绘制为可扩展到LinearLayout的Key类的背景的选择器,在单击它时未显示任何效果。
public class Key extends LinearLayout {
LinearLayout keyContainer;
public Key(Context context,AttributeSet attrs) {
super(context,attrs);
setBackground(ContextCompat.getDrawable(context,R.drawable.selector_color));
setClickable(true);
setFocusable(true);
this.init(attrs);
this.keyContainer = (LinearLayout) inflate(context,R.layout.text_key,this);
}
private void init(AttributeSet attrs) {
...
}
}
selector_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<color android:color="@color/semitransparent_white" />
</item>
<item>
<color android:color="@color/transparent" />
</item>
</selector>
如果我将背景添加到膨胀的布局中,这将起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。