Android 线性布局半透明(但不透明)

Android 线性布局半透明(但不透明),android,layout,Android,Layout,我想要一个半透明的线性布局(我不是说透明)。 我想在活动中模拟对话。所以我试了一下: 在舱单中: android:theme="@android:style/Theme.Translucent" 在活动onCreate中: LinearLayout MyLayout = (LinearLayout)findViewById(R.id.MyLayout); MyLayout.setBackgroundColor(Color.BLACK); MyLayout.getBackground().

我想要一个半透明的线性布局(我不是说透明)。 我想在活动中模拟对话。所以我试了一下:

在舱单中:

android:theme="@android:style/Theme.Translucent"
在活动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>

使用十六进制颜色代码,其中两位数字表示alpha,六位数字表示颜色本身,如下所示:

android:background="#22FFFFFF"

这会使它变成半透明的。

对不起,它对我不起作用。此外,我必须将“22FFFFFF”改为“#22FFFFFF”。@deliver如果您计划使整个活动半透明,则需要确保活动使用透明主题。