Jungerr/GridPasswordView

能否添加一个获取焦点的方法

Opened this issue · 5 comments

现在view不点击不会自动获取焦点

gridPasswordView.postDelayed(new Runnable() { @Override public void run() { gridPasswordView.forceInputViewGetFocus(); } },100);

需要把 forceInputViewGetFocus 改为public的

无法改动源码,有什么好的解决方案ma?^_^

@w3812127 ctrl c ctrl v.

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);
}

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);
}

使用反射是正解😆