Android DialogFragment with AppCompat theme issue

前端 未结 3 1782
温柔的废话
温柔的废话 2021-02-08 10:23

I\'ve trying to create DialoFragment with AppCompat theme, but when i use AppCompat theme, dialog title is not shown.

I\'am using defined style:



        
相关标签:
3条回答
  • 2021-02-08 10:24

    Theme.AppCompat.Light.Dialog sets no title window in default.

    Try something like below:

    <style name="DialogFragment" parent="Theme.AppCompat.Light.Dialog">
       <item name="android:windowNoTitle">false</item>
    </style>
    
    0 讨论(0)
  • 2021-02-08 10:45

    As far as i know once you override onCreateView you are overriding the default layout of the dialogFragment. so i suggest that you create the whole custom dialog fragment layout.

    here's a sample xml layout.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="match_parent"
                  android:background="@drawable/rounded_dialog"
                  android:orientation="vertical"
                  android:padding="@dimen/margin_standard">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="@dimen/margin_standard"
            >
    
    
            <TextView
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:id="@+id/dialog_error_prompt_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginBottom="@dimen/margin_standard"
            android:layout_marginLeft="@dimen/horizontal_margin"
            android:layout_marginRight="@dimen/margin_standard"
            android:layout_marginTop="@dimen/margin_standard"
            >
            <TextView
                android:id="@+id/dialog_error_prompt_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem_long"
                />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:orientation="horizontal"
            android:weightSum="1"
            android:padding="@dimen/margin_standard">
    
            <TextView
                android:visibility="invisible"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="@dimen/margin_standard"
                android:clickable="true"
                android:padding="@dimen/margin_standard"
                android:text="@string/cancel"
                android:textAppearance="?android:attr/textAppearanceButton"
                android:layout_weight=".70"
                android:gravity="center"
                android:textColor="@color/primary"/>
    
            <TextView
                android:gravity="center"
                android:layout_weight=".30"
                android:id="@+id/dialog_error_prompt_positive_button"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/standard_button_height"
                android:layout_margin="@dimen/margin_standard"
                android:background="@drawable/primary_button_selector_background"
                android:clickable="true"
                android:padding="@dimen/margin_standard"
                android:text="@string/ok"`enter code here`
                android:textAppearance="?android:attr/textAppearanceButton"
                android:textColor="@color/background_floating_material_light"/>
        </LinearLayout>
    </LinearLayout>
    
    0 讨论(0)
  • 2021-02-08 10:46

    Try extending AppCompatDialogFragment instead of DialogFragment. That should do the trick.

    0 讨论(0)
提交回复
热议问题