能否添加一个获取焦点的方法
Opened this issue · 5 comments
star-andy commented
现在view不点击不会自动获取焦点
CSnowStack commented
gridPasswordView.postDelayed(new Runnable() { @Override public void run() { gridPasswordView.forceInputViewGetFocus(); } },100);
需要把 forceInputViewGetFocus 改为public的
w3812127 commented
无法改动源码,有什么好的解决方案ma?^_^
HotBitmapGG commented
@w3812127 ctrl c ctrl v.
w3812127 commented
passwordView.postDelayed(new Runnable() { @OverRide public void run() {
try {
setObjectFunction(passwordView);
}catch (Exception e){
e.printStackTrace();
}
} },100);
}
public static void setObjectFunction(Object obj) throws SecurityException, NoSuchMethodException,
IllegalArgumentException, InvocationTargetException, IllegalAccessException {
Class cls = obj.getClass();
// 获得类的私有方法
Method method = cls.getDeclaredMethod("forceInputViewGetFocus", null);
method.setAccessible(true); // 没有设置就会报错,设置可以调用私有方法。
// 调用该方法
method.invoke(obj, null);
}
1130381752 commented
passwordView.postDelayed(new Runnable() { @OverRide public void run() {
try {
setObjectFunction(passwordView);
}catch (Exception e){
e.printStackTrace();
}
} },100);
}public static void setObjectFunction(Object obj) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException, IllegalAccessException { Class cls = obj.getClass(); // 获得类的私有方法 Method method = cls.getDeclaredMethod("forceInputViewGetFocus", null); method.setAccessible(true); // 没有设置就会报错,设置可以调用私有方法。 // 调用该方法 method.invoke(obj, null); }
使用反射是正解😆