android 如何依赖android:sharedUserId更换皮肤Skin(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-19 21:54 点击:次
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textview = (TextView)findViewById(R.id.id_skin_textview);
textview.setText("皮肤一");
linearLayout = (LinearLayout)findViewById(R.id.id_skin_linearlayout);
linearLayout.setBackgroundColor(Color.BLUE);
try {
//获取皮肤共享的数据包
ctx = this.createPackageContext("com.tal.skin", CONTEXT_IGNORE_SECURITY);②
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bt1 = (Button)findViewById(R.id.id_skin_bt1);
bt2 = (Button)findViewById(R.id.id_skin_bt2);
bt3 = (Button)findViewById(R.id.id_skin_bt3);
bt1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
linearLayout.setBackgroundColor(Color.BLUE);
textview.setText("默认皮肤");
}});
bt2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
linearLayout.setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.skin1)); ③
textview.setText("皮肤一");
}});
bt3.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
linearLayout.setBackgroundDrawable(ctx.getResources().getDrawable(R.drawable.skin2));④
textview.setText("皮肤二");
}});
}
}
注解:②③④获取皮肤工程的数据,当中有指定皮肤的包名
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/id_skin_linearlayout"
>
<TextView
android:id="@+id/id_skin_textview"
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>