简体   繁体   English

如何使android布局背景透明?

[英]How to make android layout background transparent?

使android布局背景透明

How to make RecyclerView item background transparent I need to show background image?如何使RecyclerView项目背景透明我需要显示背景图像?

I tried 3 solutions given in Stack Overflow and not worked for me我尝试了Stack Overflow 中给出的 3 个解决方案,但对我不起作用

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

udated i also tried日期我也试过
4: android:background="@null" (Answer from this post) and not working 4:android:background="@null"(来自这篇文章的答案)并且不工作

full xml code 完整的xml代码

尝试在您的项目CardView上提供此CardView

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

Try this:尝试这个:

1) In your manifest make that activity theme to Transparent- 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) Now your page will be 100% transparent, so if you need some background color then set opacity like- 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" >

it helps you.它可以帮助你。

So for the layout you are inflating for the item you can use android:background="@null"因此,对于您为项目膨胀的布局,您可以使用android:background="@null"

You can also use developer options on your device to see layout bounds or check the view hierarchy to see which item is giving you problems您还可以使用设备上的开发人员选项来查看布局边界或检查视图层次结构以查看哪个项目给您带来了问题

First add this style in styles.xml首先在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>

then add this line in AndroidManifest.xml below the corresponding activity然后在 AndroidManifest.xml 中相应活动下方添加此行

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

hope it helps.希望能帮助到你。

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

set transparent color in your view在您的视图中设置透明颜色

#80000000 #80000000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM