جافا
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
SharedPreferences shard ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
shard = getSharedPreferences("Setting", Context.MODE_PRIVATE);
int myStyle = shard.getInt("myStyle",0);
switch (myStyle){
case 0:
this.setTheme(R.style.AppTheme);
break;
case 1:
this.setTheme(R.style.AppTheme1);
break;
case 2:
this.setTheme(R.style.AppTheme2);
break;
}
setContentView(R.layout.activity_main);
findViewById(R.id.btn_0).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyStyle(0);
}
});
findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyStyle(1);
}
});
findViewById(R.id.btn_2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyStyle(2);
}
});
}
public void MyStyle(int myStyle){
SharedPreferences.Editor editor = shard.edit();
editor.putInt("myStyle",myStyle);
editor.apply();
finish();
startActivity(new Intent(this, MainActivity.class));
}
}
<TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:layout_width="wrap_content"
android:text="Theme 0"
android:id="@+id/btn_0"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:text="Theme 1"
android:id="@+id/btn_1"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:text="Theme 2"
android:id="@+id/btn_2"
android:layout_height="wrap_content" />
colors
colors
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#042aff</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="color_1">#009311</color>
<color name="color_2">#015c0b</color>
<color name="color_3">#f28d00</color>
<color name="color_10">#8c00ff</color>
<color name="color_20">#5900a1</color>
<color name="color_30">#00b49f</color>
</resources>
style
style
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/color_1</item>
<item name="colorPrimaryDark">@color/color_2</item>
<item name="colorAccent">@color/color_3</item>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
<item name="colorPrimary">@color/color_10</item>
<item name="colorPrimaryDark">@color/color_20</item>
<item name="colorAccent">@color/color_30</item>
</style>
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
SharedPreferences shard ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
shard = getSharedPreferences("Setting", Context.MODE_PRIVATE);
int myStyle = shard.getInt("myStyle",0);
switch (myStyle){
case 0:
this.setTheme(R.style.AppTheme);
break;
case 1:
this.setTheme(R.style.AppTheme1);
break;
case 2:
this.setTheme(R.style.AppTheme2);
break;
}
setContentView(R.layout.activity_main);
findViewById(R.id.btn_0).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyStyle(0);
}
});
findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyStyle(1);
}
});
findViewById(R.id.btn_2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MyStyle(2);
}
});
}
public void MyStyle(int myStyle){
SharedPreferences.Editor editor = shard.edit();
editor.putInt("myStyle",myStyle);
editor.apply();
finish();
startActivity(new Intent(this, MainActivity.class));
}
}
<TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:layout_width="wrap_content"
android:text="Theme 0"
android:id="@+id/btn_0"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:text="Theme 1"
android:id="@+id/btn_1"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:text="Theme 2"
android:id="@+id/btn_2"
android:layout_height="wrap_content" />
colors
colors
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#042aff</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="color_1">#009311</color>
<color name="color_2">#015c0b</color>
<color name="color_3">#f28d00</color>
<color name="color_10">#8c00ff</color>
<color name="color_20">#5900a1</color>
<color name="color_30">#00b49f</color>
</resources>
style
style
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/color_1</item>
<item name="colorPrimaryDark">@color/color_2</item>
<item name="colorAccent">@color/color_3</item>
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
<item name="colorPrimary">@color/color_10</item>
<item name="colorPrimaryDark">@color/color_20</item>
<item name="colorAccent">@color/color_30</item>
</style>
</resources><resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. --><item name="colorPrimary">@color/color_1</item><item name="colorPrimaryDark">@color/color_2</item><item name="colorAccent">@color/color_3</item></style><style name="AppTheme2" parent="Theme.AppCompat.Light"><!-- Customize your theme here. --><item name="android:windowFullscreen">true</item><item name="colorPrimary">@color/color_10</item><item name="colorPrimaryDark">@color/color_20</item><item name="colorAccent">@color/color_30</item></style></resources>
ليست هناك تعليقات:
إرسال تعليق