、、、、、、、、、、、、values-night |
<?xml version= "1.0" encoding= "utf-8" ?> |
<resources> |
<color name= "colorPrimary" >#ff333333</color> |
<color name= "colorPrimaryDark" >#ff222222</color> |
<color name= "colorAccent" >#ff80bd01</color> |
<color name= "act_background_black_white" >#ff000000</color> |
<color name= "text_black_white" >#ffffff</color> |
</resources> |
//////main |
<?xml version= "1.0" encoding= "utf-8" ?> |
<LinearLayout android:background= "@color/act_background_black_white" |
android:layout_height= "match_parent" |
android:layout_width= "match_parent" |
android:orientation= "vertical" |
tools:showin= "@layout/activity_main" |
xmlns:android= "http://schemas.android.com/apk/res/android" |
xmlns:tools= "http://schemas.android.com/tools" > |
<Button |
android:layout_height= "wrap_content" |
android:layout_width= "match_parent" |
android:onClick= "modeDay" |
android:text= "白昼模式" |
android:textColor= "@color/text_black_white" > |
</Button> |
<Button |
android:layout_height= "wrap_content" |
android:layout_width= "match_parent" |
android:onClick= "modeNight" |
android:text= "夜间模式" |
android:textColor= "@color/text_black_white" > |
</Button> |
</LinearLayout> |
///////////////////////////////baseAdapter |
public class BaseActivity extends AppCompatActivity { |
private static boolean enableNightMode = false ; |
@Override |
protected void onCreate( @Nullable Bundle savedInstanceState) { |
super .onCreate(savedInstanceState); |
if (!enableNightMode) { |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); |
} else { |
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); |
} |
} |
/** |
*If enabled night mode |
* @return true or false |
*/ |
public boolean isEnableNightMode() { |
return enableNightMode; |
} |
/** |
* enable night mode or not |
* @param enableNightMode true or false |
*/ |
public void setEnableNightMode( boolean enableNightMode) { |
this .enableNightMode = enableNightMode; |
if (enableNightMode) { |
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES); |
} else { |
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO); |
} |
recreate(); |
} |
} |
//////////////////////////////mian |
public class MainActivity extends BaseActivity { |
@Override |
protected void onCreate(Bundle savedInstanceState) { |
super .onCreate(savedInstanceState); |
setContentView(R.layout.activity_main); |
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
// setSupportActionBar(toolbar); |
} |
public void modeDay(View v) { |
setEnableNightMode( false ); |
} |
public void modeNight(View v) { |
setEnableNightMode( true ); |
} |
by: 发表于:2017-09-27 10:00:03 顶(0) | 踩(0) 回复
??
回复评论