在我的Android应用程序中,我试图实现更改Theme
。我设法更改了所有想要的颜色,并且在运行时中的主题运行良好(我正在使用SharedPreferences
存储所选颜色)。
但是,当我从头开始打开应用程序时,起初默认主题可见(准确地说是ActionBar
颜色),只有一两秒钟后,加载应用程序时,颜色更改为从。
那么如何更改默认的SharedPreferences
?还是有什么方法可以改变加载时可见的颜色?
更新:我在Theme
中应用主题,这还不够。
最佳答案
我通常的建议是在清单中使用透明的全屏主题。
启动活动时,请切换到自定义主题。
与此结合,我总是建议使用alpha动画从应用程序主题过渡到活动主题。这样可以防止在自定义主题出现时对用户造成伤害。
清单主题定义为:
android:theme="@android:style/Theme.Translucent.NoTitleBar"
基本活动
onCreate()
方法:@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// set your custom theme here before setting layout
super.setTheme(android.R.style.Theme_Holo_Light_DarkActionBar);
setContentView(R.layout.activity_main);
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
基本淡入:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
基本淡出(并不是真正需要,但为了完整性):
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
有关此问题的进一步相关讨论,请查看我对以下相关问题的回答:
How to set the theme for the application, to avoid wrong color transitions?