我想要一个半透明的LinearLayout(我不是说透明)。我想在我的活动中模拟对话框。所以我试了这个:
在清单中:
android:theme="@android:style/Theme.Translucent"
在创建活动时:
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>
使用十六进制颜色代码,由两位数字组成,表示字母,六位数字表示颜色本身,如下所示:
android:background="#22FFFFFF"
它会让它半透明。