Can I change the Android phone mode (day, night, automatic) programmatically? This is not working for me:
UiModeManager manager = (UiModeManager)getSystemService(Context.UI_MODE_SERVICE);
manager.setNightMode(UiModeManager.MODE_NIGHT_YES);
Do I need to set any permissions in 开发者_C百科AndroidMaifest.xml for this?
I posted an answer to this question Here
If you decide to go with this solution, then your next step would be deciding how and when you need to switch the layout.
Using a timer you can find the current time and check with:
ViewFlipper vf = (ViewFlipper) findViewById( R.id.viewFlipper );
if (mCurrentTime == //whatever time you want) {
vf.showNext();
}
Putting this code inside a runnable can periodically check if it should switch to night (or day) mode using a viewflipper. Learn how to use a viewflipper in the link above
But be warned! If a user is using your application and for example is typing some notes, then the layout changes to a different scheme the user can Lose all their progress in the current activity - so automatic layout changes are not recommended unless handled correctly (like saving all "save-able" data to a file just before the automatic change occurs, then reinstating it after the change so the transition is smooth)
Here are some great links (also the one above) to provide you with the tools to implement an automatic layout change:
- ViewFlipper Documentation
- How to Read and Write to a file in Android
- Using a Runnable (link part 1) As a Timer (link part 2)
精彩评论