您的位置:首页 > 其它

小随笔:Context共用

2016-01-13 16:59 197 查看
[code]  //不能做为插件化开发、主要还是方法超出错误未解决


[code]
    private Context contextSkin;
    private Button butt;
    private RelativeLayout background;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setContextSkin();
        butt = (Button) findViewById(R.id.butt);
        background = (RelativeLayout) findViewById(R.id.background);
        butt.setText(R.string.skin_butt);

        setLintener();

    }

    private void setLintener() {
        butt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                butt.setText(contextSkin.getResources().getText(R.string.skin_butt));
                background.setBackgroundDrawable(contextSkin.getResources().getDrawable(R.mipmap.skin_temp));

            }
        });
    }

    private void setContextSkin() {

        try {
            contextSkin = createPackageContext("com.example.administrator.qqskin_2", Context.CONTEXT_IGNORE_SECURITY);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: