标签: dialogfragment

Android中的对话框和弹出窗口

http://developer.android.com/design/building-blocks/dialogs.html中的Android设计文档明确区分了对话框,警报,弹出窗口和Toast.它还建议通过类和Toasts通过类来实现Dialogs.但是,我不清楚是否应该使用或使用弹出窗口.DialogFragmentToastPopupWindowDialogFragment

我知道DialogFragments通常带有Ok/Cancel按钮,并且PopupWindows可以定义位置,但是:

android popup popupwindow dialogfragment

12
推荐指数
1
解决办法
4255
查看次数

Android:禁用DialogFragment确定/取消按钮

如何在使用AlertDialog创建DialogFragment时禁用"确定/取消"按钮?我尝试调用myAlertDialogFragment.getDialog(),但即使显示片段,它也始终返回null

public static class MyAlertDialogFragment extends DialogFragment {

    public static MyAlertDialogFragment newInstance(int title) {
        MyAlertDialogFragment frag = new MyAlertDialogFragment();
        Bundle args = new Bundle();
        args.putInt("title", title);
        frag.setArguments(args);
        return frag;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        int title = getArguments().getInt("title");

        return new AlertDialog.Builder(getActivity())
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(title)
                .setPositiveButton(R.string.alert_dialog_ok,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ((FragmentAlertDialog)getActivity()).doPositiveClick();
                        }
                    }
                )
                .setNegativeButton(R.string.alert_dialog_cancel,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            ((FragmentAlertDialog)getActivity()).doNegativeClick();
                        }
                    }
                )
                .create();
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过膨胀包含取消和确定按钮的布局来实现它,但我宁愿使用AlertDialog解决方案,如果可能的话

android button android-alertdialog dialogfragment

11
推荐指数
2
解决办法
1万
查看次数

如何通过setCanceledOnTouchOutside事件取消DialogFragment时隐藏屏幕键盘

如果当前正在关注edittext并且用户在DialogFragment外部单击; 我希望屏幕键盘消失.当DialogFragment以这种方式被解雇时,我可以让它工作:

InputMethodManager imm;
public View onCreateView(LayoutInflater inflator, ViewGroup container,
        Bundle savedInstanceState) {
imm = (InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
...}

@Override 
public void dismiss(){
    imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
    super.dismiss();
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试通过触摸对话片段之外取消它时同样的事情,它将无法工作.我试图通过覆盖onCancel来做到这一点:

@Override
public void onCancel(DialogInterface dialog){
    imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
    super.onCancel(dialog);
}
Run Code Online (Sandbox Code Playgroud)

当外部触摸事件发生时调用该函数,但不删除键盘.

android dialogfragment

10
推荐指数
2
解决办法
4706
查看次数

如何在Google日历应用中使用Android对话框(全屏,嵌入式)

我想要实现的目标

谷歌在其日历应用中实施的小/大屏幕行为.

例如,当您创建新事件时,在大屏幕上会打开"对话框"

  1. 这会使背景中的活动变暗
  2. 工具栏始终位于同一位置,并且永远不会被屏幕键盘推出视图
  3. 在纵向模式下,对话框工具栏的底部与活动的"扩展"工具栏的底部对齐.

    工具栏对齐w /活动工具栏

    上下文操作栏(例如用于文本选择)是在活动的工具栏上绘制的,并向下推动对话框,因此它不再与活动的工具栏相关联.

  4. 在横向模式下,它似乎固定在通知栏下方; 上下文操作栏是在活动的工具栏上绘制的

    上下文操作栏:左侧横向,右侧纵向

在小屏幕上

  1. 对话框填满了屏幕
  2. 上下文操作栏通过工具栏绘制

到目前为止我尝试过的

A.从android文档中全屏显示DialogFragment示例(不能再添加缺少声誉的b/c链接)

  • 当显示为全屏对话框时,背景是透明的,它会在通知栏上绘制(类似于沉浸式模式)

B.添加(感谢stackoverflow上的一些帖子)

  • 对话框片段样式:

    setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialogFragmentStyle);
    
    <style name="MyDialogFragmentStyle" parent="@style/MyTheme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowIsFloating">false</item>
    </style>
    
    Run Code Online (Sandbox Code Playgroud)
  • 删除了窗口标题

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    
    Run Code Online (Sandbox Code Playgroud)
  • 添加了自定义工具栏

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
      <android.support.v7.widget.Toolbar
         android:id="@+id/toolbar"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="?attr/colorPrimary"
         android:minHeight="?attr/actionBarSize"
         app:homeAsUpIndicator="@drawable/ic_arrow_back_white_24dp"
         app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    
      <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar" >
      </FrameLayout>
    
    </RelativeLayout>
    
    Run Code Online (Sandbox Code Playgroud)
  • 并在小型设备上将对话框设置为全屏

    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    
    Run Code Online (Sandbox Code Playgroud)

这有点工作,它解决了我想要达到的一些要点和A.'Android样本'问题(透明背景,...)

  1. 使背景中的活动变暗

    • 作品
  2. 工具栏始终位于同一位置,并且永远不会被屏幕键盘推出视图

    • 有点,除了工具栏被屏幕键盘推出屏幕外
  3. 在纵向模式下,对话框工具栏的底部与Activity的"扩展/大"工具栏的底部对齐.上下文操作栏(例如用于文本选择)是在活动的工具栏上绘制的,并向下推动对话框,因此它不再与活动的工具栏相关联.

    • nope,没有付出任何努力来对齐b/c 2.上下文操作栏是在Activity的工具栏上绘制的,并且是对话框工具栏的一部分.
  4. 在横向模式下,它似乎固定在通知栏下方; 上下文操作栏是在活动的工具栏上绘制的.

    • 不,屏幕上的键盘按下工具栏从屏幕和上下文动作栏上绘制活动的工具栏,也超过了对话的一部分(B/C对话框的工具栏被外推 - …

android screen-size dialogfragment

10
推荐指数
0
解决办法
786
查看次数

AutoCompleteTextView仅允许建议的选项

我有一个DialogFragment包含AutoCompleteTextView,以及CancelOK按钮.

AutoCompleteTextView是给我是从服务器获取用户名的建议.

我想要做的是限制用户只能输入现有的用户名.

我知道我可以在用户点击时检查该用户名是否存在OK,但是还有其他方式,假设如果不存在此类用户名,则不允许用户输入字符.我不知道该怎么做,因为在每个输入的角色上我只得到5个建议.服务器以这种方式实现.

欢迎任何建议.谢谢

android autocompletetextview android-dialogfragment dialogfragment

9
推荐指数
1
解决办法
4967
查看次数

在平板电脑上显示DialogFragment时隐藏键盘?

我使用DialogFragmentListView(列出所有客户)和EditText(从列表中进行搜索),它的正常工作.但是,每当从片段显示对话框时,始终显示键盘并且用户需要辞职.有没有办法在显示对话框片段时第一次隐藏它?然后,当用户点击编辑文本时,键盘应该出现.

我已经尝试android:focusable="false"在我的XML中进行设置但是,它在点击后也总是隐藏键盘EditText也没有显示.

然后我尝试设置,android:focusableInTouchMode="true"但是,如上所述

keyboard android show-hide dialogfragment

9
推荐指数
1
解决办法
6119
查看次数

全屏DialogFragment与StatusBar重叠

我使用官方指南创建了一个全屏对话框

问题是,我的工具栏与状态栏重叠,我无法弄清楚如何解决这个问题.

DialogFragment

public class CreateAccountDialogFragment extends BaseDialogFragment {

    @Inject
    CreateAccountViewModel viewModel;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //InjectDependencies....
        View rootView = createDataBinding(inflater, container);
        createToolbar(rootView);

        return rootView;
    }

    private View createDataBinding(LayoutInflater inflater, ViewGroup container) {
        CreateAccountDialogFragmentBinding binding =
                DataBindingUtil.inflate(inflater, R.layout.create_account_dialog_fragment, container, false);
        binding.setViewModel(viewModel);
        return binding.getRoot();
    }

    private void createToolbar(View rootView) {
        Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

        // Set an OnMenuItemClickListener to handle menu item clicks
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) { …
Run Code Online (Sandbox Code Playgroud)

java android dialog android-fragments dialogfragment

9
推荐指数
2
解决办法
4849
查看次数

DialogFragment在Android 4.4.2中有蓝线

在此输入图像描述

我的对话框片段顶部出现了一条蓝线,我无法摆脱(我甚至不知道为什么它出现在第一位.有人知道如何摆脱这个吗?

我已经在几个设备上测试了它,它在以后的Android版本上运行得很好.

我的代码:

    private void setupDialog() {
    final Dialog dialog = getDialog();
    final Window window = dialog.getWindow();

    window.setBackgroundDrawable(new ColorDrawable(0));
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
Run Code Online (Sandbox Code Playgroud)

布局:

      <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tiktok="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/settings_bg">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">

        <ImageView
            android:id="@+id/close_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_margin="15dp"
            android:src="@drawable/pressable_close_btn"/>

        <com.cyscorpions.timekeeper.customviews.TKTextView
            android:id="@+id/settings_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/dp_40"
            android:text="@string/settings_allcaps"
            android:textColor="@color/timekeeper_blue"
            android:textSize="@dimen/sp_60"
            tiktok:useBoldFont="true"/>

        <com.cyscorpions.timekeeper.customviews.TKTextView
            android:id="@+id/account_name_instruction"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/settings_title"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/dp_20"
            android:text="@string/subdomain_instruction"
            android:textColor="@color/gray"
            android:textSize="@dimen/sp_30"/>

        <RelativeLayout
            android:id="@+id/info_field"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/dp_70"
            android:layout_alignLeft="@+id/submit_btn"
            android:layout_below="@id/account_name_instruction"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="@dimen/dp_20">

            <com.cyscorpions.timekeeper.customviews.TKAppCompatEditText
                android:id="@+id/subdomain_textfield"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@drawable/text_field_bg"
                android:hint="@string/textfield_account_hint"
                android:inputType="text"
                android:textColor="@color/gray" …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-dialogfragment dialogfragment

9
推荐指数
1
解决办法
2154
查看次数

什么是DialogFragment的生命周期

android.support.v4.app.DialogFragment在Google上搜索找不到合适的生命周期.我需要这个用于一些实现.我们知道DialogFragment有一些相同的方法Dialog.

DialogFragment延伸Fragment所以它的生命周期与之相同Fragment.但是其他方法DialogFragment呢?

这是Fragment生命周期.可以提供DialogFragment吗?

在此输入图像描述

android android-dialogfragment dialogfragment appcompatdialogfragment

9
推荐指数
2
解决办法
9492
查看次数

从“底部工作表”对话框片段中获取价值

我从片段A开始bottomSheetDialogFragment。我想从该bottomSheetDialogFragment中选择日期,然后将其设置在片段A中。

选择日期已经完成,我只想将其放在片段A中以在某些字段中进行设置。

我如何获得价值?有什么建议怎么做吗?

android fragment dialogfragment bottom-sheet

8
推荐指数
3
解决办法
4072
查看次数