android通过泛型获取控件或视图】的更多相关文章

@SuppressWarnings("unchecked") public <T extends Fragment> T getFragment(int id) { T result = (T)getFragmentManager().findFragmentById(id); if (result == null) { throw new IllegalArgumentException("fragment 0x" + Integer.toHexStr…
有时候我们需要动态的取得一个一个控件的id,然后进行操作,经过在网上查找,找到了一下方法getResources().getIdentifier("textView01", "id", "cn.xxx.xxx"); 第一个参数为ID名,第二个为资源属性是ID或者是Drawable,第三个为包名. 以下是从网上找到资料:主要由两种方法,个人建议第二种. 1. 不把图片放在res/drawable下,而是存放在src某个package中(如:com.…
Android自动化测试中AccessibilityService获取控件信息(2)-三种方式对比   上一篇文章: Android自动化测试中AccessibilityService获取控件信息(1) 已经做到了获得控件信息,但是AccessibilityEvent.getSource()得到的是被点击的单体对象.我们需要获得是整个窗口的对象,在API16中AccessibilityService新引入的方法getRootInActiveWindow()可以满足我们的要求,所以我们用这个方法得…
Android自动化测试中AccessibilityService获取控件信息(1) 分类: android自动化测试2014-03-24 15:31 3455人阅读 评论(16) 收藏 举报 android自动化AccessibilityService   目录(?)[+]   AccessibilityService为一个响应用户发送AccessibilityEvent事件的服务类,主要用作对于一些辅助功能的实现中.对于某些方面有缺陷的人群,可以通过辅助功能反馈给用户. Accessibil…
1.获取Android屏幕尺寸 我们能够通过getSize()方法获得屏幕的尺寸 Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y; 假设不是在Activity里面.则无法使用getWindowManager().此时能够使用WINDOW_SERVICE获…
(一)获取屏幕的高度和宽度 有两种方法: 方法1: WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);   int width = wm.getDefaultDisplay().getWidth();   int height = wm.getDefaultDisplay().getHeight(); 方法2: WindowManager wm = this.getWi…
mBtnNews = (Button)findViewById(R.id.btn_news);//获取控件…
获取屏幕宽高 // 获取屏幕宽高(方法1) int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); // 屏幕宽(像素,如:480px) int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); // 屏幕高(像素,如:800p) Log.e(TAG + " getDefaultDisplay", "screen…
一.获取屏幕宽高: (1). WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); int width = wm.getDefaultDisplay().getWidth(); int height = wm.getDefaultDisplay().getHeight(); (2). WindowManager wm = this.getWindowManager(); int width = wm…
有时候我们须要在Activity的时候获取控件的宽和高来做一些操作,以下介绍三种获取宽和高的方式: 1. onWindowFocusChanged @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { int width = image.getMeasuredWidth(); int height = image.ge…