3

我想要一个 LinearLayout 半透明(我不是说透明)。我想在我的活动中模拟一个对话框。所以我尝试了这个:

在清单中:

android:theme="@android:style/Theme.Translucent"

在 Activity onCreate 中:

LinearLayout MyLayout = (LinearLayout)findViewById(R.id.MyLayout);  
MyLayout.setBackgroundColor(Color.BLACK); 
MyLayout.getBackground().setAlpha(50);

但它不起作用,因为我根本看不到主桌面。任何的想法?

我也在 xml 中尝试过这个,但它也不起作用:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/MyLayout"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="#22FFFFFF"
   android:orientation="vertical" >
</LinearLayout>
4

1 回答 1

2

使用十六进制颜色代码,其中包含 alpha 的两个数字和颜色本身的六个数字,如下所示:

android:background="#22FFFFFF"

它会使它变成半透明的。

于 2012-05-12T12:04:34.960 回答