mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Add dialog examples with outlined or filled buttons.
PiperOrigin-RevId: 256185197
This commit is contained in:
parent
15f2a245e1
commit
0271cec540
@ -20,6 +20,7 @@ import io.material.catalog.R;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.StyleRes;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
@ -207,9 +208,39 @@ public class DialogMainDemoFragment extends DemoFragment {
|
||||
.setPositiveButton(R.string.short_text_1, null)
|
||||
.setNeutralButton(R.string.short_text_2, null));
|
||||
|
||||
// title, outlined buttons
|
||||
addDialogLauncher(
|
||||
dialogLaunchersLayout,
|
||||
R.string.title_outlined_buttons,
|
||||
new MaterialAlertDialogBuilder(getContext(), getOutlinedButtonThemeOverlay())
|
||||
.setTitle(title)
|
||||
.setPositiveButton(positiveText, null)
|
||||
.setNegativeButton(negativeText, null)
|
||||
.setNeutralButton(neutralText, null));
|
||||
|
||||
// title, filled buttons
|
||||
addDialogLauncher(
|
||||
dialogLaunchersLayout,
|
||||
R.string.title_filled_buttons,
|
||||
new MaterialAlertDialogBuilder(getContext(), getFilledButtonThemeOverlay())
|
||||
.setTitle(title)
|
||||
.setPositiveButton(positiveText, null)
|
||||
.setNegativeButton(negativeText, null)
|
||||
.setNeutralButton(neutralText, null));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@StyleRes
|
||||
protected int getFilledButtonThemeOverlay() {
|
||||
return R.style.ThemeOverlay_Catalog_MaterialAlertDialog_FilledButton;
|
||||
}
|
||||
|
||||
@StyleRes
|
||||
protected int getOutlinedButtonThemeOverlay() {
|
||||
return R.style.ThemeOverlay_Catalog_MaterialAlertDialog_OutlinedButton;
|
||||
}
|
||||
|
||||
private void addDialogLauncher(
|
||||
ViewGroup viewGroup, @StringRes int stringResId, AlertDialog.Builder alertDialogBuilder) {
|
||||
MaterialButton dialogLauncherButton = new MaterialButton(viewGroup.getContext());
|
||||
|
||||
@ -52,6 +52,10 @@
|
||||
<string name="title_scrolling">Scrolling Content</string>
|
||||
<!-- Denotes what parts of an AlertDialog this button will display. [CHAR LIMIT=60] -->
|
||||
<string name="title_2_short_actions">Short Buttons</string>
|
||||
<!-- Denotes button emphasis in an AlertDialog this button will display. [CHAR LIMIT=60] -->
|
||||
<string name="title_outlined_buttons">Outlined buttons</string>
|
||||
<!-- Denotes button emphasis in an AlertDialog this button will display. [CHAR LIMIT=60] -->
|
||||
<string name="title_filled_buttons">Filled buttons</string>
|
||||
|
||||
<!-- Text for a positive dialog action. [CHAR LIMIT=15] -->
|
||||
<string name="positive">Accept</string>
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<style name="Widget.Catalog.Button.OutlinedButton.Dialog" parent="Widget.MaterialComponents.Button.OutlinedButton">
|
||||
<item name="android:minWidth">@dimen/mtrl_btn_dialog_btn_min_width</item>
|
||||
<item name="android:lines">1</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
<item name="android:layout_marginStart">@dimen/mtrl_btn_text_btn_padding_left</item>
|
||||
<item name="android:layout_marginLeft">@dimen/mtrl_btn_text_btn_padding_left</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.Catalog.Button.Dialog" parent="Widget.MaterialComponents.Button">
|
||||
<item name="android:minWidth">@dimen/mtrl_btn_dialog_btn_min_width</item>
|
||||
<item name="android:lines">1</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
<item name="android:layout_marginStart">@dimen/mtrl_btn_text_btn_padding_left</item>
|
||||
<item name="android:layout_marginLeft">@dimen/mtrl_btn_text_btn_padding_left</item>
|
||||
</style>
|
||||
</resources>
|
||||
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<!-- A theme overlay for Alert Dialog panels with a outlined buttons. -->
|
||||
<style name="ThemeOverlay.Catalog.MaterialAlertDialog.OutlinedButton" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
|
||||
<item name="buttonBarButtonStyle">@style/Widget.Catalog.Button.OutlinedButton.Dialog</item>
|
||||
<!--<item name="buttonBarPositiveButtonStyle">@style/Widget.Catalog.Button.OutlinedButton.Dialog</item>-->
|
||||
<!--<item name="buttonBarNegativeButtonStyle">@style/Widget.Catalog.Button.OutlinedButton.Dialog</item>-->
|
||||
<!--<item name="buttonBarNeutralButtonStyle">@style/Widget.Catalog.Button.OutlinedButton.Dialog</item>-->
|
||||
</style>
|
||||
|
||||
<!-- A theme overlay for Alert Dialog panels with filled buttons. -->
|
||||
<style name="ThemeOverlay.Catalog.MaterialAlertDialog.FilledButton" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
|
||||
<!--<item name="buttonBarButtonStyle">@style/Widget.Catalog.Button.Dialog</item>-->
|
||||
<item name="buttonBarPositiveButtonStyle">@style/Widget.Catalog.Button.Dialog</item>
|
||||
<item name="buttonBarNegativeButtonStyle">@style/Widget.Catalog.Button.Dialog</item>
|
||||
<item name="buttonBarNeutralButtonStyle">@style/Widget.Catalog.Button.Dialog</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
Loading…
x
Reference in New Issue
Block a user