以编程方式更改启动画面颜色
Change Splash Screen Color Programmatically
我使用以下方法以编程方式更改初始屏幕颜色,但 DrawableLayer 的 FindDrawableLayerById
returns 为空值。
protected override void OnCreate(Bundle bundleSavedInstanceState)
{
base.OnCreate(bundleSavedInstanceState);
LayerDrawable layerDrawable = (LayerDrawable)ContextCompat.GetDrawable(this, Resource.Drawable.XMLFileSplashScreen);
GradientDrawable gradientDrawable = (GradientDrawable)layerDrawable.FindDrawableByLayerId(Resource.Id.itemSplashScreenColor);
gradientDrawable.SetColor(Resource.Color.Blue);
}
您可以按照 here
所述将 layer-list
与 <item android:drawable=”@color/colorPrimary” />
一起使用
如果您有线性或相对布局,请在您的 oncreate 方法中像这样设置背景颜色:
LinearLayout chglayout = (LinearLayout ) findViewById(R.layout.the_id);
chglayout.setBackgroundColor(Color.parseColor("#000000"));
我的问题由此解决:
<item name="android:windowDisablePreview">true</item>
final FrameLayout frm = (FrameLayout)findViewById(R.id.FramId);
frm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
frm.setBackgroundColor(getResources().getColor(R.color.colorEndBlue));
}
});
我使用以下方法以编程方式更改初始屏幕颜色,但 DrawableLayer 的 FindDrawableLayerById
returns 为空值。
protected override void OnCreate(Bundle bundleSavedInstanceState)
{
base.OnCreate(bundleSavedInstanceState);
LayerDrawable layerDrawable = (LayerDrawable)ContextCompat.GetDrawable(this, Resource.Drawable.XMLFileSplashScreen);
GradientDrawable gradientDrawable = (GradientDrawable)layerDrawable.FindDrawableByLayerId(Resource.Id.itemSplashScreenColor);
gradientDrawable.SetColor(Resource.Color.Blue);
}
您可以按照 here
所述将layer-list
与 <item android:drawable=”@color/colorPrimary” />
一起使用
如果您有线性或相对布局,请在您的 oncreate 方法中像这样设置背景颜色:
LinearLayout chglayout = (LinearLayout ) findViewById(R.layout.the_id);
chglayout.setBackgroundColor(Color.parseColor("#000000"));
我的问题由此解决:
<item name="android:windowDisablePreview">true</item>
final FrameLayout frm = (FrameLayout)findViewById(R.id.FramId);
frm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
frm.setBackgroundColor(getResources().getColor(R.color.colorEndBlue));
}
});