我有一个扩展了Dialog的“ Message.java” java类
public class InBoxMessageCustomDialogClass extends Dialog {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_OPTIONS_PANEL);
setContentView(R.layout.layout_dialog_inbox_message);
}
和“ message_style”我的对话框样式:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="sfsdfsdfsd" />
我的活动是:
InBoxMessageCustomDialogClass dialogClass = new InBoxMessageCustomDialogClass(getContext(),
dialogClass.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogClass.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialogClass.setCanceledOnTouchOutside(true);
dialogClass.show();
如何使这种对话框样式像角对话框?
答案 0 :(得分:0)
像这样更改您的布局
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
答案 1 :(得分:0)
您创建可绘制对象:res / drawable / dialog_bg:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="@android:color/white"/>
<corners
android:radius="30dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
在layout_dialog_inbox_message中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/dialog_bg">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="sfsdfsdfsd" />
</RelativeLayout>
使用时:
InBoxMessageCustomDialogClass dialogClass = new
InBoxMessageCustomDialogClass(getContext(),
dialogClass.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogClass.getWindow().setBackgroundDrawable(new
ColorDrawable(android.graphics.Color.TRANSPARENT));
dialogClass.setCanceledOnTouchOutside(true);
dialogClass.show();
结果:
答案 2 :(得分:-1)
使用CardView
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="5dp">
//view Inside
</android.support.v7.widget.CardView>
并添加card_view:cardCornerRadius="5dp"
以提供拐角半径。