【问题标题】:Android Application : Background Image over Background ColorAndroid应用程序:背景颜色的背景图像
【发布时间】:2012-07-14 11:32:09
【问题描述】:

我是 android 开发新手,正在开发我的第一个 android 应用程序。我在布局的 xml 中设置了 View 的背景颜色,如下所示。

android:background="@+color/bgColor"

现在,我有一个全尺寸的透明背景图像,我想将其放在背景上,然后将其他元素放在该图像上。

有没有办法可以在同一布局中同时使用背景颜色和背景图像。

提前致谢。

【问题讨论】:

    标签: android android-layout background-image background-color


    【解决方案1】:

    您可以使用带有背景颜色的 ImageView:

    <ImageView
        layout_width="match_parent"
        layout_height="match_parent"
        src="@drawable/myImage"
        background="@color/myBgColor" />
    

    另一种选择是在布局的根元素中设置背景颜色,并将 src 保留在 ImageView 中。

    【讨论】:

    • 完美,正是我想要的。谢谢。
    【解决方案2】:

    我正在使用AppCompatImageView。在这个背景颜色可以使用下面的属性来设置。

    android:backgroundTint="@color/colorPrimary"
    

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 2017-08-11
      相关资源
      最近更新 更多