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
version3.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>如果你发现自己在多个地方使用这个,那么考虑在中描述一个<代码>对话片段< /代码>子类。
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();
}
}