我想使用带有默认警报对话框的新材料轮廓按钮。
我在style.xml中创建了样式,如下所示
<style name="OutlinedButton" parent="Widget.MaterialComponents.Button.TextButton">
<item name="strokeColor">@color/colorAccent</item>
<item name="strokeWidth">2dp</item>
</style>
<style name="MaterialDialogStyle" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="android:textColorPrimary">@color/colorAccent</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimary">@color/colorAccent</item>
<item name="buttonStyle">@style/OutlinedButton</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我正在使用新的 Material Components 主题来设置“是”和“否”按钮的样式。
现在,我通过将其设置为 AlertDialog 构建器来在代码中使用上述样式。
AlertDialog.Builder builder = new AlertDialog.Builder(ProductListActivity.this, R.style.MaterialDialogStyle);
Run Code Online (Sandbox Code Playgroud)
有没有办法将最新材料概述按钮与默认警报对话框一起使用?如果有什么区别的话,我正在使用设计支持库中的材料组件。
android android-alertdialog android-styles material-design material-components-android
有什么方法可以更改默认对话框按钮的颜色,或者我需要为此做自定义对话框吗?
这是我的对话:
private void removeItem(final int position) {
/** Create dialog which ask if user is sure about delete name from list **/
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Delete player");
builder.setIcon(R.mipmap.ic_launcher);
builder.setMessage("Do you want to delete player: \"" + mNameList.get(position).getText1() + "\"?")
.setCancelable(false)
/** If user click "ok" button, delete player from list and save changes **/
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mNameList.remove(position);
mAdapter.notifyItemRemoved(position);
saveData();
}
})
/** If user click "cancel" button, …Run Code Online (Sandbox Code Playgroud) android android-alertdialog material-design material-components material-components-android