Closed farsunset closed 6 years ago
已经在1.6.2-SNAPSHOT
上实现,你可以添加以下仓库后,引入1.6.2-SNAPSHOT
版本进行验证:
allprojects {
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
好的,谢谢
@Jacksgong 使用快照版本这样无效 api 'cn.dreamtobe.kpswitch:library:1.6.2-SNAPSHOT'
@r17171709 你要先参考上面提到的申明仓库,anyway,我已经发布了1.6.2,你可以直接使用1.6.2了。
感谢官方支持该功能,之前项目中采用hook performClick
来实现
@r17171709 实在不行可以试试我的方案,将需要知道被点击的view用PostClickImageView
替换
@SuppressLint("AppCompatCustomView")
public class PostClickImageView extends ImageView {
private OnPostClickListener onPostClickListener;
public PostClickImageView(Context context) {
super(context);
}
public PostClickImageView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public PostClickImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public PostClickImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean performClick() {
boolean shouldClick = super.performClick();
if (shouldClick && onPostClickListener != null) {
onPostClickListener.performClick(this);
}
return shouldClick;
}
public static interface OnPostClickListener {
void performClick(View v);
}
public void setOnPostClickListener(OnPostClickListener onPostClickListener) {
this.onPostClickListener = onPostClickListener;
}
}
@Harlber 点击事件的回调没有修复啊,1.6.2的代码中依然是
if (switchClickListener != null && switchToPanel != null) {
switchClickListener.onClickSwitch(v, switchToPanel);
}
那你可以试试上面我提及的hook performClick
的方式,我项目中用的解决方案 @chentao7v
大佬。1.6.2这个功能是加上了,但是有个bug ,场景如下 2个Switch 分别为Switch1, Switch2 当前panel1为Switch1,这个时候点击Switch2,切换到panel2,功能没有问题,但是onClickSwitch回调没有触发,这个时候再点击一次Switch2才会触发,我希望只要是点击了Switch,就一定回调onClickSwitch,希望早日解决,谢谢;
可以给点击的View设置setOnTouchListener,这个是在onClick之前执行的,如果返回true,还可以屏蔽掉点击事件
能否在SwitchClickListener返回被点击的View,多个panel的情况下,需要这个View来做一些判断。还有如何在登录页面记录下来 键盘高度,这样就不需要使用min-panel-height的配置了