7

今天我正在尝试新的材料组件,它们的安装部分是您需要更改应用程序的父级以从 Theme.MaterialComponents 继承。所以我这样做是因为我想使用具有更好波纹的底部导航。但在那之后,应用程序中的几乎所有按钮都变得更加臃肿。

我应该怎么做才能恢复到以前的状态(右图)?

左边是material版本,右边是appcompat版本 左边是material版本,右边是appcompat版本

4

3 回答 3

13

在研究过程中,我找到了答案,我会把它留在这里,也许它会对某人有所帮助。

它们看起来像这样的原因是因为它们使用style="attr/buttonBarNegativeButtonStyle"并且 Material 主题会覆盖它们

要解决此问题,您需要使用 Bridge 主题而不是Theme.MaterialComponents.Light

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.Bridge">
    <!-- ... -->
</style>

更多信息: https ://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#bridge-themes

于 2018-09-12T10:28:32.813 回答
3

另一种方法是使用AlertDialogAndroidX AppCompat 库:

AlertDialog signInDialog = new AlertDialog.Builder(this)
    .setMessage("Are you sure you want to log out?")
    .setPositiveButton("OK", (dialogInterface, i) -> {
        // TODO: Add your code here
    })
    .setNegativeButton("Cancel", (dialogInterface, i) -> {
        // TODO: Add your code here
    })
signInDialog.show();

注意:如果您正在使用Android 库的 Material Components和/或您正在使用新的Theme.MaterialComponents.*主题,您应该使用MaterialAlertDialogBuilderclass,它应该用来代替 AppCompatAlertDialog类,如下所述:

Material 维护了 framework 的使用AlertDialog,但提供了一个新的 builder ,MaterialAlertDialogBuilder它使用 Material 规范和主题配置实例化的 AlertDialog。

这是一个示例(在 Kotlin 中):

MaterialAlertDialogBuilder(this).apply {
    setMessage("Are you sure you want to log out?")
    setPositiveButton("OK") {
        TODO("Unimplemented functionality")
    }
    setNegativeButton("Cancel") {
        TODO("Unimplemented functionality")
    }
}.show()
于 2018-09-16T04:12:20.350 回答
1

Solution

停止使用android.app.AlertDialog并更换 androidx.appcompat.app.AlertDialog它会解决您的问题

You can use

    <style name="AppTheme" parent="@style/Theme.MaterialComponents.Light.Bridge">
    </style>

    or

    <style name="AppTheme" parent="@style/Theme.MaterialComponents.Light.NoActionBar.Bridge">
    </style>       

但是当你使用材料组件时,它会导致你ExtendedFloatingActionButtonMaterialButton

于 2019-09-30T06:02:32.337 回答