有两个页面,分别是不同的布局有各自的xml文件,在当前页我可以通过
View v = findViewById(R.id.main);
v.getBackground().setAlpha(0);来设置背景透明度,但我想在当前页面
用同样方法设置另一个页面透明度就会报空指针错误,请各位大侠帮我解决下
谢谢了

解决方案 »

  1.   

    findViewById()只能找到setContentView()的部件,也就是当前页的部件,所以你要先获取那个非当前页。用getLayoutIInflate()获取inflater对象,然后使用inflate()方法获取目标页面layout,然后layout.findViewById()就可以了。
            LayoutInflater inflater = getLayoutInflater();    
            View layout = inflater.inflate(R.layout.custom_dialog,null);   
            TextView text = (TextView) layout.findViewById(R.id.text);