【问题标题】:How to show an ImageView in a style?如何以样式显示 ImageView?
【发布时间】:2017-01-01 00:15:12
【问题描述】:

之前,当我的应用程序第一次启动时,会出现白屏。所以我在styles.xml 中创建了一个黑色背景的样式,并在我的清单中引用了它:

    <activity
        android:name=".InitialScreen"
        android:theme="@style/Theme.Transparent"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

styles.xml:

  <style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:background">#000</item>
</style>

黑屏显示成功,如何显示这种风格的ImageView?

【问题讨论】:

    标签: android xml android-layout android-studio android-styles


    【解决方案1】:

    在项目的 mipmap/drawables 文件夹中添加您选择的图像。在您的样式中删除背景并添加一个 windowBackground... 在内部引用您添加的可绘制对象或 mipmap。

    例如:

    我希望我的背景是某个图像,它的名称将是background.png。我将转到我的项目目录并将此图像添加到 drawables 或 mipmaps 文件夹中,具体取决于您使用的是哪个。在你的风格有这样的:

    android:windowBackground="@drawable/background"
    

    @mipmap/background,取决于您使用的是哪个。

    为什么我使用 windowBackground 而不是 background

    我最近刚刚做了同样的事情,并意识到我在使用背景而不是 windowBackground 时犯了一个错误,因为如果你有一个没有指定背景的布局/视图,它将使用相同的背景。这将导致背景重复。

    希望我能帮上忙,

    -丹尼尔

    【讨论】:

      猜你喜欢
      • 2011-09-05
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 2016-04-03
      相关资源
      最近更新 更多