2016-06-29 20 views
0

Ich habe ein Problem mit AlertDialog - Dialog hat keine Polsterung (wie auf Screenshot - Dialog ohne Polsterung innen).Android-Dialog hat keine Polsterung

Meine Tätigkeit hat Thema "NoActionBar"

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

Meine Aktivität:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    Button button = (Button) findViewById(R.id.button); 
    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      showDial(); 
     } 
    }); 
} 

private void showDial() { 
    new AlertDialog.Builder(this) 
      .setTitle("Delete entry") 
      .setMessage("Are you sure you want to delete this entry?") 
      .setPositiveButton("tak", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        // continue with delete 
       } 
      }) 
      .show(); 
} 

Weiß jemand, wie man es beheben?

Antwort

0

Sie müssen benutzerdefinierte Ansicht in Ihrem Dialog Alarm

private void showDial() { 

    View content = this.getLayoutInflater().inflate(R.layout.custom_dialog_alert, null); 
    ((TextView)content.findViewById(R.id.dialogTitle)).setText("Delete entry"); 
    ((TextView)content.findViewById(R.id.dialogText)).setText("Are you sure you want to delete this entry?"); 


    AlertDialog alert = new AlertDialog.Builder(Test.this, R.style.no_title_dialog) 
      .setCancelable(true) 
      .setPositiveButton("tak", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        // continue with delete 
       } 
      }) 
      .setView(content) 
      .create(); 
    alert.show(); 
} 

custom_dialog_alert.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:background="@android:color/holo_red_light"> 

<TextView 
    android:id="@+id/dialogTitle" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:paddingTop="10dp" 
    android:ellipsize="end" 
    android:gravity="left" 
    android:lines="1" 
    android:paddingLeft="26dp" 
    android:paddingRight="10dp" 
    android:text="Dialog title" 
    android:textColor="@android:color/black" 
    android:background="@android:color/background_light" 
    android:textSize="20sp" /> 

<RelativeLayout 
    android:id="@+id/contentText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/background_light" 
    android:minHeight="40dp" 
    android:paddingTop="10dp"> 

     <TextView 
      android:id="@+id/dialogText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:gravity="left" 
      android:maxHeight="300dp" 
      android:text="Dialog text" 
      /> 
</RelativeLayout> 

no_title_dialog in styles.xml

<style name="no_title_dialog" parent="Theme.AppCompat.Light.Dialog"> 
    <item name="android:windowNoTitle">true</item> 
</style> 

Ich hoffe, es verwenden h elps

0

Fügen Sie diesen Stil Ihrem Dialog hinzu.