渲染对话框元素的材质设计风格



我正在创建一个使用复选框布局的对话框片段。然而,我从来没有能够渲染它们的材料设计外观在pre-棒棒糖设备。然而,我能够在一个常规的活动中完成它。在处理DialogFragments时,我该怎么做?

这些是我的DialogFragment代码的一部分:

 @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.Theme_AppCompat_Dialog);
        Window window = dialog.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.getAttributes().windowAnimations = R.style.Share_Multiplayer_Animation;
        return dialog;
    }
 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.share_multiplayer_scorecard, container, false);
        ButterKnife.bind(this, view);
        ViewGroup shareContainer = ButterKnife.findById(view, R.id.container);
        List<MultiplayerRound> multiplayerRoundList = mRound.getMultiplayerRoundList();
        for (int i = 0; i < multiplayerRoundList.size(); i++) {
            MultiplayerRound mpRound = multiplayerRoundList.get(i);
            View rowView = inflater.inflate(R.layout.multiplayer_share_row, shareContainer, false);
            TextView nameTv = ButterKnife.findById(rowView, R.id.et_name);
            nameTv.setText(mpRound.getName());
            CheckBox checkBox = ButterKnife.findById(rowView, R.id.cb_send_scorecard);
            final EditText emailET = ButterKnife.findById(rowView, R.id.et_email);
            emailET.addTextChangedListener(new CheckboxControllerTextWatcher(checkBox));
            emailET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    emailET.setSelection(emailET.getText().length());
                }
            });
            String email = getEmail(mpRound);
            emailET.setText(email);
            updateCheckboxState(email, checkBox);
            shareContainer.addView(rowView);
            mPlayerViews[i] = rowView;
            rowView.setTag(mpRound);
        }
        return view;
    }

这是我的对话框布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="@dimen/activity_vertical_margin">
    <com.devspark.robototextview.widget.RobotoTextView
        android:id="@+id/tv_title"
        style="@style/MaterialDialog.Title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="@string/round.multiplayer.share.scorecard"/>
    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:orientation="vertical"/>
    <LinearLayout
        style="@style/MaterialDialog.ButtonBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp">
        <com.devspark.robototextview.widget.RobotoButton
            android:id="@+id/btn_dismiss"
            style="@style/MaterialDialog.Button"
            android:layout_width="wrap_content"
            android:text="@string/share_dismiss"/>
        <com.devspark.robototextview.widget.RobotoButton
            android:id="@+id/btn_send"
            style="@style/MaterialDialog.Button"
            android:layout_width="wrap_content"
            android:text="@string/action_send"/>
    </LinearLayout>
</LinearLayout>

谢谢。

从AppCompat的第23版开始,你可以使用AppCompatDialogFragment来创建一个材料设计DialogFragment,它是兼容Android 2.1的

相关内容

  • 没有找到相关文章

最新更新