LiangLuDev / DevShapeUtils

一行代码设置Shape样式、Selector触摸反馈效果开源库
166 stars 17 forks source link

state_enabled 状态会影响click事件 #6

Open NickTet opened 6 years ago

NickTet commented 6 years ago

state_enabled 状态会影响click事件

NickTet commented 6 years ago

@Override public void into(View view) { //TextView等view默认没有点击事件,所以针对view初始化点击事件 view.setOnClickListener(null); view.setBackground(createDrawableSelector()); if (isSelectorTextColor) { try { int[] colors = new int[]{mSelectTextColor, mNormalTextColor}; int[][] states = new int[2][]; states[0] = new int[]{state}; states[1] = new int[]{-state}; ((TextView) view).setTextColor(new ColorStateList(states, colors)); } catch (Exception e) { e.printStackTrace(); throw new ExceptionInInitializerError("设置字体颜色选择器(Selector)请传入TextView(或者TextView的子类,比如Button)!!!"); } } } 请问一下为什么into(view)的时候要把listener设置为null,这样butterknifie的点击事件就没用了

LiangLuDev commented 6 years ago

@NickTet 感谢反馈 这个是因为设置Button之外View的selector 默认是没有触摸事件的。这个我后面更新兼容一下。

wss991 commented 5 years ago

view.setOnClickListener(null); 个人觉得没必要加这行代码,如果加上了就出现下面情况 比如一个view先设置.setOnClickListener,然后再设置shape 此时点击事件就会无效。

LiangLuDev commented 5 years ago

@wang869755676 这个已经有的新的想法,后面会更新