Android 7.1.1上的DatePicker添加了额外的填充/边距

前端之家收集整理的这篇文章主要介绍了Android 7.1.1上的DatePicker添加了额外的填充/边距前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个显示DatePicker的自定义对话框,但该元素在视图右侧添加了额外的边距/填充.这种情况仅发生在 Android 7.1.1,Nexus 6P上,但在其他低分辨率手机上运行得非常好.如何删除额外的填充?
我的XML布局代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <DatePicker
        android:id="@+id/date_picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:endYear="2012"
        android:startYear="1930" />

</LinearLayout>

在Android 7.1.1上看起来像这样:

编辑:添加了我的Java代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_attributes);

    assert getSupportActionBar() != null;
    getSupportActionBar().setTitle("Register");

    final TextView birthDateSelectedTextView = (TextView) findViewById(R.id.text_view_birth_date);
    Button dialogopenButton = (Button) findViewById(R.id.button_dialog_date_picker);
    dialogopenButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(UserAttributesActivity.this);
            final AlertDialog.Builder builder = new AlertDialog.Builder(UserAttributesActivity.this);
            LayoutInflater inflater = getLayoutInflater();
            View dialogView = inflater.inflate(R.layout.dialog_date_picker,null);
            builder.setView(dialogView);
            final DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.date_picker);

            builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog,int which) {
                    day = datePicker.getDayOfMonth();
                    month = datePicker.getMonth() + 1;
                    year = datePicker.getYear();
                    String date = "" + day + "/" + month + "/" + year;
                    birthDateSelectedTextView.setText(date);
                }
            });
            builder.setNegativeButton("Cancel",int which) {
                }
            });
            builder.show();
        }
    });
}

解决方法

使用AlertDialog.Builder添加样式,如下所示.
AlertDialog.Builder builder = new AlertDialog.Builder(UserAttributesActivity.this,android.R.style.Theme_DeviceDefault_Light_Dialog_NoActionBar);
原文链接:https://www.f2er.com/android/308631.html

猜你在找的Android相关文章