怎么获取屏幕上的控件信息?

tableter 2018-11-28 10:24:53
不知道有哪些办法能获取到当前屏幕上的控件。
...全文
406 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fei得更高 2018-11-30
  • 打赏
  • 举报
回复
引用 2 楼 tableter 的回复:
[quote=引用 1 楼 键盘舞者113的回复:]可以获取控件的信息,但是你不能直接获取控件的对象变量引用

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


我的意思是其它程序的组件,不是自己的程序。[/quote]
这个android应该不会直接有什么方法可以实现的
雕·不懒惰 2018-11-30
  • 打赏
  • 举报
回复
Accessibility 了解下
https://www.jianshu.com/p/432344392f82
键盘舞者113 2018-11-29
  • 打赏
  • 举报
回复
可以获取控件的信息,但是你不能直接获取控件的对象变量引用

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

tableter 2018-11-29
  • 打赏
  • 举报
回复
引用 1 楼 键盘舞者113的回复:
可以获取控件的信息,但是你不能直接获取控件的对象变量引用

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

我的意思是其它程序的组件,不是自己的程序。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧