不知道有哪些办法能获取到当前屏幕上的控件。

解决方案 »

  1.   

    可以获取控件的信息,但是你不能直接获取控件的对象变量引用@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {    LayoutInflaterCompat.setFactory2(LayoutInflater.from(this), new LayoutInflater.Factory2() {
            //'这个方法是Factory接口里面的,因为Factory2是继承Factory的'
            @Override
            public View onCreateView(String name, Context context, AttributeSet attrs) {
                return null;
            }
            
            //'这个方法是Factory2里面定义的方法'
            @Override
            public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
                Log.e(TAG, "parent:" + parent + ",name = " + name);
                int n = attrs.getAttributeCount();
                for (int i = 0; i < n; i++) {
                    Log.e(TAG, attrs.getAttributeName(i) + " , " + attrs.getAttributeValue(i));
                }
                return null;
            }
            
        });    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test1);
    }
      

  2.   

    我的意思是其它程序的组件,不是自己的程序。
    这个android应该不会直接有什么方法可以实现的
      

  3.   

    Accessibility 了解下
    https://www.jianshu.com/p/432344392f82