android自定义view背景透明度,Android线性布局,将背景设置为透明

我在充气

bottom_sheet_layout

. 它包含一个LinearLayout作为根元素。它有一张儿童卡。

我试过以下方法:

setting `android:background` property to

1. #00FFFFFF

2. #00000000

3. @android:color/transparent

setting the background color of LinearLayout programatically

`LinearLayout l = container.findViewById(R.id.root_element);

l.setBackgroundColor(Color.TRANSPARENT);`

这是

BottomSheet.Class

底部板材布局

@Override

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.bottom_sheet_layout, container, false);

LinearLayout l = container.findViewById(R.id.root_element);

l.setBackgroundColor(Color.TRANSPARENT);

return v;

}

已经满了

底部板材布局

android:id="@+id/root_element"

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_margin="16dp">

xmlns:card_view="http://schemas.android.com/apk/res-auto"

android:id="@+id/card_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="8dp"

card_view:cardCornerRadius="4dp">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/poiName"

android:fontFamily="@font/comfortaa_bold"

android:text="@string/poiName"

android:textSize="20sp"

android:layout_marginTop="20dp"

android:layout_marginLeft="20dp"

android:layout_marginBottom="20dp"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="20dp"

android:layout_marginRight="20dp"

android:layout_marginBottom="10dp"

android:fontFamily="@font/work_sans_medium"

android:text="@string/ui_location"

android:textFontWeight="800" />

android:id="@+id/location"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="20dp"

android:layout_marginRight="20dp"

android:layout_marginBottom="10dp"

android:fontFamily="@font/work_sans"

android:text="@string/ui_location_addr" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:layout_marginTop="10dp"

android:layout_marginBottom="20dp"

android:layout_marginRight="20dp"

android:src="@drawable/share"

android:scaleType="center"

card_view:backgroundTint="@color/colorPrimary" />

这是

Map Fragment

. 这里是我充气的地方

底部板材布局

xmlns:map="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/map"

android:name="com.google.android.gms.maps.SupportMapFragment"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MapsActivity" />

跟着几位导游,我还是找不到

#00FFFFFF

工作方法。以编程方式将颜色设置为透明,会导致应用程序崩溃。

在前面关于StackOverflow的问题中,似乎将背景设置为使用alpha值的十六进制代码。现在我只得到一个暗淡的灰色背景。

应用程序的屏幕截图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值