gpt4 book ai didi

android - DialogFragment ~ 部分可见的对话框按钮

转载 作者:行者123 更新时间:2023-11-29 21:25:22 25 4
gpt4 key购买 nike

我正在设计一个自定义对话框(使用 DialogFragment),它会提示允许用户选择日期的日历 View 。显示对话框,但“确定”和“取消”仅部分可见。 Here is the screenshot for your reference.

这是我自定义的dialogfragment类

public class GetDateDialogFragment extends DialogFragment implements android.content.DialogInterface.OnClickListener {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
LayoutInflater inflater = getActivity().getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

View calendarView = inflater.inflate(R.layout.activity_datepicker, null);
calendarView.findViewById(R.id.btnOk).setVisibility(View.INVISIBLE);
calendarView.findViewById(R.id.btnCancel).setVisibility(View.INVISIBLE);
builder.setView(calendarView);

AlertDialog dialog = builder.setTitle(R.string.datetitle).setMessage("Please enter Date")
.setPositiveButton("OK", this).setNegativeButton("Cancel", null).create();
dialog.show();


dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, 600);

//position the buttons
//Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
//positiveButton.setY(positiveButton.getY()-100);

//Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
//negativeButton.setY(negativeButton.getY()-100);

return dialog;
}

请在下面找到布局 activity_datepicker.xml 的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="250dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" />

<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_alignRight="@id/calendarView"
android:text="@string/btnOk" />

<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/calendarView"
android:layout_alignParentBottom="true"
android:text="@string/btnCancel" />

最佳答案

尝试将 ok cacel 按钮的可见性设置为消失而不是不可见

LayoutInflater inflater = this.getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(this);

View calendarView = inflater
.inflate(R.layout.activity_datepicker, null);
calendarView.findViewById(R.id.btnOk).setVisibility(View.GONE);
calendarView.findViewById(R.id.btnCancel).setVisibility(View.GONE);
builder.setView(calendarView);

AlertDialog dialog = builder.setTitle("dfd")
.setMessage("Please enter Date").setPositiveButton("OK", null)
.setNegativeButton("Cancel", null).create();
dialog.show();

dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);

关于android - DialogFragment ~ 部分可见的对话框按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20285366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com