【问题标题】:How to make android layout background transparent?如何使android布局背景透明?
【发布时间】:2020-08-16 15:26:06
【问题描述】:

如何使RecyclerView项目背景透明我需要显示背景图片?

我尝试了 Stack Overflow 中给出的 3 种解决方案,但对我没有用

1 : android:background="?android:attr/selectableItemBackground"<br>
2 : android:background="@android:color/transparent"<br>
3 : alpfha 0.4

我也试过了
4: android:background="@null" (来自这篇文章的答案)并且不工作

full xml code

【问题讨论】:

  • 你能发布你用于布局的代码吗?
  • 对不起,当我尝试添加代码堆栈时显示“正文限制为 30000 个字符;您输入了 31496。看起来您的帖子主要是代码;请添加更多详细信息。”跨度>
  • 是的,你可以只发布相关部分,只是你想要透明的视图的 xml
  • 更新了请查收
  • 您应该尝试将您的 xml 分离到单独的文件中,以便它更加模块化和可维护。许多视图都有@null 背景,因此它们不会显示背景

标签: android android-layout


【解决方案1】:

试着在你的物品上注明CardView

 app:cardBackgroundColor="@android:color/transparent"

【讨论】:

  • 如何以编程方式设置?
  • cardView.setCardBackgroundColor(ContextCompat.getColor(mContext,R.color.transparentColor));或 cardView.setCardBackgroundColor(Color.TRANSPARENT)
【解决方案2】:

试试这个:

1) 在您的清单中将该活动主题设为透明-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhub4you.transparent.background"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<application
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.androidhub4you.transparent.background.MainActivity"
        android:theme="@android:style/Theme.transparent"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

2) 现在您的页面将 100% 透明,因此如果您需要一些背景颜色,请设置不透明度 -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
tools:context=".MainActivity" >

它可以帮助你。

【讨论】:

    【解决方案3】:

    因此,对于您正在为您可以使用的项目充气的布局 android:background="@null"

    您还可以使用设备上的开发人员选项来查看布局边界或检查视图层次结构以查看哪个项目给您带来问题

    【讨论】:

      【解决方案4】:

      首先在styles.xml中添加这个样式

      <style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
          <item name="android:windowIsTranslucent">true</item>
          <item name="android:windowBackground">@android:color/transparent</item>
          <item name="android:windowContentOverlay">@null</item>
          <item name="android:windowNoTitle">true</item>
          <item name="android:backgroundDimEnabled">true</item>
          <item name="colorPrimaryDark">@android:color/transparent</item>
      </style>
      

      然后在AndroidManifest.xml中对应activity下面添加这一行

      android:theme="@style/Theme.Transparent"/>
      

      希望对你有帮助。

      【讨论】:

        【解决方案5】:

        将所有布局 backgrouncolor= '#00000000' 也设置为您的 Recycleview 背景颜色以实现此视图

        【讨论】:

          【解决方案6】:

          在视图中设置透明色

          #80000000

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-03-02
            • 1970-01-01
            • 2022-11-15
            • 2021-01-07
            相关资源
            最近更新 更多