0

In my app I use many dialogs (popups) and I want to give them a rounded corner shape.

The way I create these popups is this:

On java code I create a function like this:

private void showpopup(){

   dialog = new Dialog(this);
   dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(getLayoutInflater().inflate(R.layout.popup, null));
   dialog.setCancelable(false);



    TextView fin = (TextView) dialog.findViewById(R.id.solu);
    fin.setText("¡¡safsfasfsafs!!");  


   fin.setOnClickListener(new OnClickListener() {
           public void onClick(View v) {
               dialog.dismiss();
               }

   });   
  dialog.show();
}

The layout I call there is created in this way:

<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
  >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
          android:background="@drawable/shape"
        android:orientation="vertical"
        android:padding="10dp" 
        >


<TextView
    android:id="@+id/solu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="25sp"
    android:padding="10dp"
    android:textAppearance="?android:attr/textAppearanceLarge" />
  </LinearLayout>

</LinearLayout>

and finally, the xml "shape" that I call in the background is this:

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

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

<corners android:radius="20dp"/>

<stroke
android:width="1dp"
android:color="@color/black"/>

</shape>

The result it's something like this:

enter image description here

As you can see, I don't achieve what I want...

4

1 回答 1

7

尝试从这里使用我的答案:如何获得活动的圆形对话框主题(这与您尝试做的事情相同)。创建一个自定义主题(引用您自己的可绘制形状):

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

    <style name="ThemeWithCorners" parent="android:Theme.Dialog">
        <item name="android:windowBackground">@drawable/another_test_drawable</item>
    </style>


</resources>

(这将在res/themes.xml)。然后简单地将主题添加到的构造函数中Dialog

dialog = new Dialog(this, R.style.ThemeWithCorners);
于 2012-05-22T19:05:32.343 回答