0

Ich habe meine App vor kurzem aktualisiert, um Android M (api 23) neue Änderungen zu erfüllen, und ich habe festgestellt, dass es eine große Veränderung in wie Dialoge gerendert werden.Dialog-Layout ist anders mit Android 6.0

Insbesondere der reservierte Platz verschwand und die Einschränkungen in Bezug auf Breite und Höhe werden nicht eingehalten.

Dies passiert für alle Dialoge und insbesondere unten können Sie sehen, wie der Abmeldedialog des gleichen Builds auf einem Gerät api 22 (links) vs api 23 (rechts) installiert aussieht.

dialog difference

Wie kann ich die gleiche Darstellung auf allen Geräten haben, erreichen?

Hier ist die benutzerdefinierte XML für den Dialog

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

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="16dp"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:text="text message" 
      android:id="@+id/confirmDialogMessage" 
      android:layout_marginTop="8dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:weightSum="1" 
     android:background="@color/blue_mp" > 

     <ImageButton 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/confirmDialogNo" 
      android:layout_weight="0.5" 
      android:scaleType="fitStart" 
      android:src="@drawable/cancelicon" 
      android:layout_marginLeft="20dp" 
      android:background="@android:color/transparent" /> 

     <ImageButton 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/confirmDialogYes" 
      android:layout_weight="0.5" 
      android:src="@drawable/okicon" 
      android:scaleType="fitEnd" 
      android:layout_marginRight="20dp" 
      android:background="@android:color/transparent" /> 
    </LinearLayout> 
</LinearLayout> 

Dialog auf diese Weise dargestellt:

dialog = new Dialog(v.getContext()); 
dialog.setContentView(R.layout.dialog_confirm_refuse_layout); 
dialog.setTitle(getString(R.string.options_logout)); 
dialog.show(); 

EDIT: Könnten Sie mir auch erklären, warum das Rendering Wechsel zwischen api 22 und api auftritt 23?

Antwort

3

Machen Sie Ihre Eltern Layout Relative.

<?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"> 

    <LinearLayout 
      android:id="@+id/text" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="16dp"> 
     <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:text="text message" 
       android:id="@+id/confirmDialogMessage" 
       android:layout_marginTop="8dp" /> 
    </LinearLayout> 

    <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:weightSum="1" 
      android:layout_below="@id/text" 
      android:background="@color/secondary_blue" > 

     <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/invite" 
       android:layout_weight="0.5" 
       android:scaleType="fitStart" 
       android:src="@drawable/y_cross_btn" 
       android:layout_marginLeft="20dp" 
       android:background="@android:color/transparent" /> 

     <ImageButton 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:id="@+id/close" 
       android:layout_weight="0.5" 
       android:src="@drawable/ic_tick_btn" 
       android:scaleType="fitEnd" 
       android:layout_marginRight="20dp" 
       android:background="@android:color/transparent" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

Danke, dies funktioniert, aber um den Titel zu zeigen Ich habe herausgefunden, wie es von hier aus http://stackoverflow.com/a/32711916/5546499 – LucioB

0

Sie können beim Ausrichten der Schaltflächen und Ändern der Bildschaltfläche in die Bildansicht von Linear Layout zu Relative Layout wechseln.

Anbringen der Beispielcode:

<RelativeLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="50dp" 
    android:background="@color/pricing_blue" > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/confirmDialogNo" 
     android:src="@drawable/button_green" 
     android:layout_marginLeft="20dp" 
     android:layout_alignParentLeft="true" 
     android:background="@android:color/transparent" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/confirmDialogYes" 
     android:src="@drawable/button_green" 
     android:layout_marginRight="20dp" 
     android:layout_alignParentRight="true" 
     android:background="@android:color/transparent" /> 
</RelativeLayout> 
Verwandte Themen