Android: расположение заголовка для диалогового окна предупреждения находится ниже линии - PullRequest
0 голосов
/ 14 октября 2018

Отображается диалоговое окно с предупреждением при нажатии одного из элементов в списке.Все хорошо, за исключением того, что расположение заголовка для диалога неверно, как показано на рисунке ниже.Почему заголовок расположен под строкой, а не над строкой?

enter image description here

Код диалогового окна предупреждения

ListView listView = (ListView)findViewById(R.id.listView);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,
                android.R.style.Theme_Holo_Light_Dialog);
        View view2 = getLayoutInflater().inflate(R.layout.dialog,null);
        builder.setView(view2);
        builder.setTitle("Edit")
                .setCancelable(false)
                // Add action buttons
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        //
                        refreshData();
                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                })
                .setIcon(android.R.drawable.ic_menu_edit)
                .show();
    }
});

Расположениедиалоговое окно оповещения

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dialog_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp">

    <EditText
        android:id="@+id/edittext_date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Date"
        android:inputType="text" />

    <EditText
        android:id="@+id/edittext_point"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Point"
        android:inputType="numberSigned" />

    <EditText
        android:id="@+id/edittext_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Description"
        android:inputType="text" />

</LinearLayout>     

1 Ответ

0 голосов
/ 18 октября 2018

Вы используете устаревший стиль для диалога.Попробуйте это:

final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

Это нормально работает для меня.


РЕДАКТИРОВАТЬ

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->  
    ...
    <item name="alertDialogTheme">@style/AlertDialogStyle</item> 
    ...
</style>
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">#c0ff00</item>
    <item name="android:titleTextStyle">@style/MyTextStyle</item>
</style>
...