加载前设置初始背景颜色

AVE*_*imi 6 android android-activity

我怎样才能设置活动的背景颜色setContentView.我有一个活动,需要花费大量的时间来加载,我需要保持背景白色,直到活动完成加载.

Nar*_*ngh 9

我想这正是你需要的.

首先在values/colors.xml中定义颜色

<resources>
    <color name="background">#FFFFFF </color>
</resources>
Run Code Online (Sandbox Code Playgroud)

在res /值中创建一个引用该颜色的themes.xml文件:

<resources>
 <style name="MyTheme" parent="@android:style/Theme.Light"> 
  <item name="android:windowBackground">@color/background</item>
 </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

...然后在AndroidManifest.xml中将此指定为您要使用的活动的主题.

<activity
        android:name=".MyActivity"
        android:theme="@style/MyTheme" />
Run Code Online (Sandbox Code Playgroud)


Rak*_*ani 0

在你的 oncreate 添加以下内容

Spinner = (ProgressBar) findViewById(R.id.LoginPageProgressBar);
    Spinner.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)

当您单击按钮时,在使用意图之前添加以下内容

Spinner.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)