如何删除Android

时间:2017-02-17 13:26:16

标签: android dialog alertdialog android-alertdialog

我正在显示一个显示一些列表数据的AlertDialog但是Dialog和数据的标题没有显示在相同的对齐中,从左边到AlertDialog's标题有一些额外的填充,而Dialog看起来像这个:

enter image description here

代码:

 AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Search on the basis of :");
    builder.setCancelable(false);
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(OrdersActivity.this, android.R.layout.select_dialog_item);
    arrayAdapter.add("Order Name");
    arrayAdapter.add("Order Date");
    builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String strName = arrayAdapter.getItem(which);
            adapter.searchType(strName);
        }
    });
    builder.show();

有谁能告诉我如何从对话框标题中删除多余的填充?

3 个答案:

答案 0 :(得分:0)

使用此选项设置减少alertdialogbox的填充 setPadding(0,0,0,0);

答案 1 :(得分:0)

设置警报对话框的自定义标题视图。并为标题文本视图设置适当的填充。

TextView textView = new TextView(this);

textView.setText("Search on the basis of :");

textView.setPadding(50,50,10,10);

builder.setCustomTitle(textView);

答案 2 :(得分:0)

试试这个:

更改行:

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

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogTheme);

并在styles.xml中添加与您的主题版本对应的父项。

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <!-- Customize your theme here. -->
    <item name="android:windowBackground">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
</style>