Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android在MaterialDialog中居中对齐或右对齐标题和消息_Android_Kotlin_Dialog_Material Dialog - Fatal编程技术网

Android在MaterialDialog中居中对齐或右对齐标题和消息

Android在MaterialDialog中居中对齐或右对齐标题和消息,android,kotlin,dialog,material-dialog,Android,Kotlin,Dialog,Material Dialog,我在地址中使用MaterialDialogversion3.1.1 我想在对话框中对齐右边或中间的标题和消息,但在文档中找不到如何做到这一点 我查看此页面,有人使用MaterialDialog.Builder如下代码: new MaterialDialog.Builder(MainActivity.this) .titleGravity(GravityEnum.END) .contentGravity(Gravity

我在地址中使用
MaterialDialog
version
3.1.1

我想在对话框中对齐右边或中间的标题和消息,但在文档中找不到如何做到这一点

我查看此页面,有人使用
MaterialDialog.Builder
如下代码:

new MaterialDialog.Builder(MainActivity.this)
                    .titleGravity(GravityEnum.END)
                    .contentGravity(GravityEnum.END)
                    .title("چقدر عجله داری بابا!")
                    .content("این ویژگی در نسخه‌ی بعدی فعال خواهد شد! برو بعدن بیا!")
                    .positiveText("باشه. :(")
                    .negativeText("چه بهد")
                    .typeface("iran_sans_bold","iran_sans")
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            Log.wtf("+","shod");
                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            Log.wtf("-","shod");
                        }
                    })
                    .show();
但它在这个版本中被删除。我该怎么做

更新1:
支持基于android系统语言更改layoutDirection,但我有不同的情况,我希望基于内容更改layoutDirection

您不能使用默认对话框。但显然,您可以从对话框上自己的布局开始

自定义警报对话框 这个完整的示例包括将数据传递回活动

创建自定义布局 对于这个简单的示例,使用了一个带有
EditText
的布局,但是您可以用任何您喜欢的内容替换它

custom_layout.xml

笔记
    <> LI>如果你发现自己在多个地方使用这个,那么考虑在中描述一个<代码>对话片段< /代码>子类。
另见

使用材料内组件库,我只需将文本对齐到中心或右侧即可。因为这个库有很好的功能,如果它完成了,我知道我可以在Android上完成,而不需要任何库,但我想使用我提到的库(用于提到的库功能)。@peyman这是一个对话框。这里应该有哪些功能?)您可以以相同的方式将自定义布局传递到“材质”对话框。请参阅。我还在github的
MaterialDialog
中使用
文件
颜色
库@afollestad(MaterialDialog的创建者)完成了基于系统语言的布局方向(我认为这很糟糕),但我的应用程序必须基于内容显示方向(想象一个语言教程应用程序)。我没有时间创建我自己的设计,并且临时使用更改清单来完成它,以
android:supportsRtl=“false”
tools:replace=“android:supportsRtl”
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:paddingLeft="20dp"
              android:paddingRight="20dp"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
public class MainActivity extends AppCompatActivity {

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

    public void showAlertDialogButtonClicked(View view) {

        // create an alert builder
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Name");

        // set the custom layout
        final View customLayout = getLayoutInflater().inflate(R.layout.custom_layout, null);
        builder.setView(customLayout);

        // add a button
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // send data from the AlertDialog to the Activity
                EditText editText = customLayout.findViewById(R.id.editText);
                sendDialogDataToActivity(editText.getText().toString());
            }
        });

        // create and show the alert dialog
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    // do something with the data coming from the AlertDialog
    private void sendDialogDataToActivity(String data) {
        Toast.makeText(this, data, Toast.LENGTH_SHORT).show();
    }
}