查看了View中含有setBackgroundResource(int id)。但是怎么获得主窗口的view。(不是imageview)
怎么得到一个更换activity中的背景图片的方法。android:background可以设置,但是只能设置一次。我想做一个android换肤的函数,每次点击一个按钮触发onClick,里面就是设置更换的背景图片的函数。但是现在遇到了问题就是在onClick中无法获得Activity的View,这也就无法使用view.setBackgroundResource(int id)。希望高手给个解答,在线等结果。
有人说了用getWindow(),但是我试过不好使,希望大家给一个好用的方法。我把我的函数写出来了:
skinButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
Log.i("skinButton", "onClick invoked.");
???.setBackgroundDrawable(R.drawable.bg1);
}catch(Exception e){
Log.e(VideoTransmission.tag, "Fail to Change Skin" + e.getMessage());
e.printStackTrace();
}
}
});
}加粗部分就是现在还不知道怎么获取view的方法,谢谢大家
怎么得到一个更换activity中的背景图片的方法。android:background可以设置,但是只能设置一次。我想做一个android换肤的函数,每次点击一个按钮触发onClick,里面就是设置更换的背景图片的函数。但是现在遇到了问题就是在onClick中无法获得Activity的View,这也就无法使用view.setBackgroundResource(int id)。希望高手给个解答,在线等结果。
有人说了用getWindow(),但是我试过不好使,希望大家给一个好用的方法。我把我的函数写出来了:
skinButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
Log.i("skinButton", "onClick invoked.");
???.setBackgroundDrawable(R.drawable.bg1);
}catch(Exception e){
Log.e(VideoTransmission.tag, "Fail to Change Skin" + e.getMessage());
e.printStackTrace();
}
}
});
}加粗部分就是现在还不知道怎么获取view的方法,谢谢大家
解决方案 »
- java.lang.NoClassDefFoundError: org.apache.mina.transport.socket.nio.NioSocketCo
- Dialog下的Builder单击事件如何能够跳转到一个新的Activity ?求教育
- 新人求指导,想学安卓开发,应该如何开始.
- [继续问] Android Apache库连接超时问题
- android开发环境中,设计代码点击控件连接到网址
- QQ通讯录的快速搜索功能
- android 4.1 HOME键无故被屏蔽
- android手机远程控制PC鼠标
- android新建SIM卡联系人限制长度的问题
- usbcamera热插拔后无法打开的问题
- 关于edittest自动换行以及图片或表情在换行时显示盖住上一行文本的情况
- 如何判断手机桌面是否已经存在某个快捷方式
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/bg1" android:oneshot="false"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_horizontal">
<TextView
android:text="Welcome!"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/welcomecolor"
android:textStyle="bold"
android:textSize="25dp"
/>
<ImageView android:id="@+id/imageview1"
android:adjustViewBounds="true" android:maxHeight="200dp"
android:maxWidth="200dp" android:scaleType="fitXY"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</ImageView>
<TextView
android:text="Please choose what you want to do below:"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:shadowColor="@color/shadowcolor"
android:shadowRadius="3.0"
android:paddingTop="20dp"
android:lines="2"
/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:stretchColumns="*"
>
<TableRow>
<Button
android:text="视频播放"
android:textColor="@color/buttoncolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"></Button>
<Button
android:text="视频采集"
android:textColor="@color/buttoncolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"></Button>
</TableRow>
<TableRow>
<Button
android:text="欢迎动画"
android:textColor="@color/buttoncolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"></Button>
<Button
android:text="换肤"
android:textColor="@color/buttoncolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button4"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/bg"
>
而且,我直接用 HelloWorld.this.getWindow().setBackgroundDrawableResource(R.drawable.icon);getWindow也可以实现,前面的HelloWorld是当前Activity的名称
我的#部分是多张drawable,点击一次按钮换取一下背景图片,请问有什么办法吗?
我的#部分是多张drawable,点击一次按钮换取一下背景图片,请问有什么办法吗?
另想请问下高手,不同activity上的更换背景咋弄