我必须做一个透明的对话框,像这个图像。我已经尝试了许多方式,如设置背景android:background="#CCFF0000"
或设置像这样的.java文件的背景颜色在android中制作透明对话框
llWhole.setBackgroundColor(Color.TRANSPARENT);
。这里llWhole
是我的xml的父母LinearLayout
。
我也在xml文件中试过android:background="@android:color/transparent"
。我也试过View.setAlpha(0.7)
。
不幸的是他们都没有帮助我创建这种布局。你能帮我解决这个问题吗?提前致谢。
我的.xml这里
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/llWhole"
android:alpha = "0.7"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:alpha = "0.7"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Are You OK?"
android:textColor="#000"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:gravity="center"
android:textSize="18sp"
android:background="#FFF"/>
<View
android:layout_width="fill_parent"
android:layout_height="40dp"
android:alpha = "0.7"
android:background="#00FFFFFF" >
</View>
<LinearLayout
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingBottom="20dp"
android:background="#00FFFFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tvOK"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:text="OK"
android:textColor="#000"
android:gravity="center"
android:textSize="18sp"
android:background="#F11"/>
<TextView
android:id="@+id/tvNo"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="NO"
android:textColor="#000"
android:gravity="center"
android:textSize="18sp"
android:background="#F11"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
注:
- 我使用
com.android.support:appcompat-v7:23.0.1
- 我的对话框是一个
android.support.v4.app.DialogFragment
我mainActivity延伸
android.support.v7.app.AppCompatActivity;
。从这个活动我显示这个DialogFragment。MyDialogFragment dialogFragment = new MyDialogFragment(); dialogFragment.show(getSupportFragmentManager(), "my_transparent_dialog");
需要看布局的对话框 – Bhargav
好吧,我更新我的问题 –
请避免嵌套布局(坏的表演),使用单RelariveLayout,来代替。 –