Image android:windowBackground属性使背景为黑色(Xamarin.android)
我想将下图作为整个Xamarin.Android应用程序的背景: 我在styles.xml中引用了基本应用程序主题中的图像: 背景适用于所有应用程序,但图像背景较暗: 数字51周围也有一些奇怪的东西 当我将android:background=@drawable/ic\u app\u background\u图像设置为活动最外层的线性布局时,它工作正常,屏幕显示如下:Image android:windowBackground属性使背景为黑色(Xamarin.android),image,xamarin.android,background,Image,Xamarin.android,Background,我想将下图作为整个Xamarin.Android应用程序的背景: 我在styles.xml中引用了基本应用程序主题中的图像: 背景适用于所有应用程序,但图像背景较暗: 数字51周围也有一些奇怪的东西 当我将android:background=@drawable/ic\u app\u background\u图像设置为活动最外层的线性布局时,它工作正常,屏幕显示如下: 如何修复android:windowBackground属性将背景设置为黑色的问题,这样我就不必将android:backgro
如何修复android:windowBackground属性将背景设置为黑色的问题,这样我就不必将android:background=@drawable/ic\u app\u background\u图像放入每个活动的线性布局中?您可以尝试以下方法: 1.在可绘图文件夹bg.xml中创建新文件名为bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/splash_background"/>
</item>
<item>
<bitmap
android:src="@drawable/splash_logo"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
4.在活动中的用法
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
// other code
}
更新:
如果要将此样式应用于所有活动,只需将以下代码添加到基本应用程序主题。我们不需要为每项活动都设置。例如:
<!-- Base application theme. parent="Theme.AppCompat.Light.DarkActionBar" -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
</style>
结果是:
有关更多详细信息,请检查:我是否必须在所有活动之前添加主题=@style/MyTheme.Splash?@Montoolivo我已更新了答案,您可以检查它。
<style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
</style>
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
// other code
}
<!-- Base application theme. parent="Theme.AppCompat.Light.DarkActionBar" -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@drawable/bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
</style>