将风格应用于活动

时间:2016-06-26 13:29:49

标签: android

我想在选择应用偏好后将样式应用到我的应用。

以下是我的MainActivity.java中的相关部分:

 private void loadPreferences(){
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    boolean Background = sharedPreferences.getBoolean("background_color", false);
    if (Background){
        LinearLayout mainLayout = (LinearLayout)findViewById(R.id.mainActivityLayout);

    }

^我想在(背景)部分中应用样式。

2 个答案:

答案 0 :(得分:1)

继续使用此颜色而不是白色。

 if (Background){
        LinearLayout mainLayout = (LinearLayout)findViewById(R.id.mainActivityLayout);
        mainLayout.setBackgroundColor(Color.WHITE);
 }

答案 1 :(得分:0)

我不相信你可以以编程方式设置样式。但是,您可以使用模板布局xml来解决它,或者您可以为视图创建自定义类

相关问题