Пользовательские углы диалогового окна не круглые - CardViewAndroid

Я работаю над приложением для Android. В приложении я создал пользовательское диалоговое окно, я создал дизайн диалогового окна с помощью CardView, но я не могу закруглить углы диалогового окна.

Я посетил много постов на Stackoverflow за помощью, но ни один из них не был полезным.

Вот мой код:

SKCDialog.java

public class SKCDialog  extends Dialog implements android.view.View.OnClickListener {

    public Activity c;
    public Dialog d;
    public Button yes, no;
    RelativeLayout closeAcessCodeDialog ;
    private EditText accessCodeText;
    private Button verifyAccessCode;
    private ImageButton closeDialog;

    public SKCDialog(Activity a) {
        super(a);
        this.c = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.access_code_dialog);


        closeAcessCodeDialog = (RelativeLayout)findViewById(R.id.closeAcessCodeDialog) ;
        accessCodeText = (EditText)findViewById(R.id.accessCodeText) ;
        verifyAccessCode = (Button)findViewById(R.id.verifyAccessCode) ;
        closeDialog = (ImageButton)findViewById(R.id.closeDialog) ;


        closeAcessCodeDialog.setOnClickListener(this);
        verifyAccessCode.setOnClickListener(this);
        closeDialog.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.closeAcessCodeDialog:
                dismiss();
                break;

            case R.id.verifyAccessCode:

                dismiss();

                break;
            case R.id.closeDialog:

                dismiss();

                break;
            default:
                break;
        }
       // dismiss();
    }

    public void closeDialog(View v){

    }
}

access_code_dialog.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardCornerRadius="30dp"
    >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ececec"
        android:orientation="vertical"
        android:focusable="true"
        android:focusableInTouchMode="true"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Access Code"
            android:hint="Enter Your Access Code"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:textSize="18sp"
            android:textStyle="bold"
            />

        <RelativeLayout
            android:id="@+id/closeAcessCodeDialog"
            android:layout_height="40dp"
            android:layout_width="40dp"
            android:layout_alignParentRight="true"
            android:gravity="center"
            >
            <ImageButton
                android:id="@+id/closeDialog"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:background="@drawable/cross"
                />

        </RelativeLayout>

        <EditText
            android:id="@+id/accessCodeText"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            android:layout_below="@+id/closeAcessCodeDialog"
            android:layout_marginTop="20dp"
            android:background="@drawable/round_corner_shape"
            />


        <Button
            android:id="@+id/verifyAccessCode"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_below="@+id/accessCodeText"
            android:paddingLeft="25dp"
            android:paddingRight="25dp"
            android:layout_marginTop="20dp"
            android:text="Submit"
            android:background="#007AFF"
            android:textColor="#fff"
           android:layout_centerHorizontal="true"
            android:layout_marginBottom="10dp"
            />

    </RelativeLayout>

</android.support.v7.widget.CardView>

Как я вызываю SKCDialog:

SKCDialog cdd=new SKCDialog(screen);
cdd.setCancelable(false);
cdd.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
cdd.show();

Пожалуйста, предложите мне, что я делаю неправильно.


person Soft Kaka    schedule 01.05.2017    source источник
comment
попробуйте добавить cdd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));   -  person Divyesh Patel    schedule 01.05.2017
comment
@DivyeshPatel попробовал предложенное вами решение, но углы все равно не круглые.   -  person Soft Kaka    schedule 01.05.2017
comment
попробуйте добавить ‹FrameLayout xmlns:android=schemas.android.com/apk/res/android xmlns:app=schemas.android.com/apk/res-auto android :layout_width=match_parent android:background=@color/transparent android:layout_height=match_parent›   -  person Divyesh Patel    schedule 01.05.2017
comment
@DivyeshPatel все еще углы не круглые.   -  person Soft Kaka    schedule 01.05.2017
comment
удалить android:background=#ececec из относительного макета и добавить app:cardBackgroundColor=#ececec в карточку   -  person Divyesh Patel    schedule 01.05.2017
comment
@DivyeshPatel Великий Человек! опубликуйте свой комментарий в качестве ответа.   -  person Soft Kaka    schedule 01.05.2017


Ответы (2)


Попробуй это:

удалять

android:background="#ececec"

из относительного макета и добавить

app:cardBackgroundColor="#ececec" 

в карточке

person Divyesh Patel    schedule 01.05.2017

Создайте файл drawable для раунда

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" android:padding="15dp">

<solid android:color="#9CD6CB"/>
<corners
    android:bottomRightRadius="15dp"
    android:bottomLeftRadius="15dp"
    android:topLeftRadius="15dp"
    android:topRightRadius="15dp"/>
</shape>

Файл макета:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="15dp">

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:background="@drawable/bg_rounded_button"
    android:focusableInTouchMode="true">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:hint="Enter Your Access Code"
        android:text="Access Code"
        android:textSize="18sp"
        android:textStyle="bold" />

    <RelativeLayout
        android:id="@+id/closeAcessCodeDialog"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:gravity="center">

        <ImageButton
            android:id="@+id/closeDialog"
            android:layout_width="25dp"
            android:layout_height="25dp" />

    </RelativeLayout>

    <EditText
        android:id="@+id/accessCodeText"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_below="@+id/closeAcessCodeDialog"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp" />


    <Button
        android:id="@+id/verifyAccessCode"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:layout_below="@+id/accessCodeText"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="20dp"
        android:background="#007AFF"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:text="Submit"
        android:textColor="#fff" />

</RelativeLayout>

</android.support.v7.widget.CardView> 
person Janak    schedule 01.05.2017