标签: material-components-android

如何更改 MaterialAlertDialogBu​​ilder 中的正/负按钮背景颜色?

取消并添加后台按钮

我正在使用MaterialAlertDialogBuilder,因为我想要圆角和白天和夜间模式。请注意,我不能使用dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));线条,因为在我的风格中,我在 style.xml 中有不同的父级,我用它根据日/夜模式设置颜色。

问题:如何更改 MaterialAlertDialogBu​​ilder 中的正/负按钮背景颜色?

请注意,可绘制背景不适用于MaterialAlertDialogBuilder

代码:

public void showNotesDialog() {
        MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this, R.style.dialogBoxStyle);
        LayoutInflater li = LayoutInflater.from(this);
        View promptsView = li.inflate(R.layout.row_note_layout, null);
        alertDialogBuilder.setView(promptsView);

        etNote = promptsView.findViewById(R.id.et_note);
        String buttonName = getString(R.string.add);
        if (!getNotes.isEmpty()) {
            buttonName = getString(R.string.update);
            etNote.getText().clear();
            etNote.setText(getNotes);
        }

        alertDialogBuilder.setPositiveButton(buttonName, null);
        alertDialogBuilder.setNegativeButton(getString(R.string.cancel), null);
        alertDialogBuilder.setNeutralButton("Clear", null);

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.setCancelable(false);


        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button buttonPositive = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
                Button buttonNegative = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE); …
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog material-components-android

1
推荐指数
1
解决办法
2721
查看次数

如何在不使用库的情况下在状态、聚焦和正常状态下应用 TextInputLayout 的自定义形状

我想设计一个自定义圆角 TextInputLayout 正如我展示的活动 TextInputLayout 的示例图像在此输入图像描述以下

我的 xml 代码是

<com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/mobile_number"
                android:inputType="number"
                android:fontFamily="@font/montserrat_regular"
                android:maxLength="10" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

它给我一个默认的 TextInputLayout。我怎样才能得到我的观点。请帮助我。样式声明中出现错误。 样式声明错误

android widget android-textinputlayout material-components material-components-android

1
推荐指数
1
解决办法
2281
查看次数

我想更改材质组件主题中的标题栏文本颜色。任何帮助将不胜感激

我尝试设置标题颜色,但它已被弃用。我尝试使用来改变颜色

  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>

  <style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
  </style>

  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/red</item>
  </style>
Run Code Online (Sandbox Code Playgroud)

如此处所述:ActionBar 文本颜色,但整个标题栏颜色在执行此操作时更改为白色。我想要做的就是将黑色标题栏文本颜色设置为白色。我也在这里尝试了这个解决方案:更改颜色标题栏,但我使用的是 MaterialComponents 主题,而使用 AppCompactThemes 会使我的应用程序崩溃。

java android android-actionbar material-components material-components-android

1
推荐指数
1
解决办法
3240
查看次数

如何在 android java 中使用指示器创建范围搜索栏?

我想在我的应用程序中创建范围搜索栏。但我无法根据图像创建完美的搜索栏。我该如何创建请告诉我任何一个。谢谢 例子

java android android-seekbar material-components-android android-slider

1
推荐指数
1
解决办法
6892
查看次数

在 Android 中以编程方式选择和取消选择 ChipGroup 内的所有芯片

我有一个芯片组,在其中以编程方式添加选择芯片,并且有一个名为“全选”的按钮,用于选择所有芯片(如果选择了其中一些芯片)和“相同的按钮”,用于通过单击取消选择所有芯片。

现在请指导我一些正确的方法,或者如果可以使用芯片组而不是芯片的ArrayList来完成,那就太好了提前感谢:)

android android-studio android-chips material-components-android

1
推荐指数
1
解决办法
4581
查看次数

如何在 ShapeableImageView 及其描边之间应用间距

我正在使用ShapeableImageView

<com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/myImage"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:scaleType="centerCrop"
        android:src="@drawable/larry"
        app:strokeColor="@color/red"
        app:strokeWidth="9dp"
        app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerCircle" />
Run Code Online (Sandbox Code Playgroud)

而且画得还不错。但是,我希望视图和笔画之间有一点间距。我已经尝试过android:padding="10dp",但这似乎不起作用。

我还尝试删除笔画属性并使用此可绘制资源来设置视图的背景:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <stroke
        android:width="9dp"
        android:color="#00FF00" />
</shape>
Run Code Online (Sandbox Code Playgroud)

但边界根本没有出现。

请问,你知道我有什么办法可以实现它吗?

android view android-imageview material-components-android

1
推荐指数
1
解决办法
2371
查看次数

如何禁用材质滑块小部件

我正在使用谷歌材质库中的滑块小部件,我需要阻止用户滑动小部件一段时间。有什么办法可以做到这一点吗?(我宁愿不使用onPositionChanged()方法)


<com.google.android.material.slider.Slider
        android:id="@+id/speakerVolumeBottomSheetSeekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/SliderMaterialTheme"
        app:labelBehavior="gone"
        android:value="0.5"
        app:thumbColor="@color/colorAccent"
        app:trackColorActive="@color/colorAccent"
        app:trackColorInactive="@color/white_22_opacity" />

Run Code Online (Sandbox Code Playgroud)

xml android kotlin material-components-android android-slider

1
推荐指数
1
解决办法
2884
查看次数

TextInputLayout Material 组件问题:此组件上的样式要求您的应用程序主题为 Theme.MaterialComponents(或后代)

我在使用 TextInputLayout 实现材质设计时遇到问题,我知道解决方案是让您的活动主题继承材质组件主题之一,但这会给我的大多数应用程序主题带来此类更改,并且需要更多时间来重构它。我想要的是应用程序上这个特定 TextInputLayout 的材质设计。

这就是我尝试过的

<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/firstName"
                style="@style/CustomInputStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="5dp"
                android:layout_weight="1"
                app:errorEnabled="true">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/fname"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/first_name"
                    android:inputType="text|textCapWords"
                    android:nextFocusDown="@id/lname"
                    android:textSize="12sp" />

</com.google.android.material.textfield.TextInputLayout>




<style name="CustomInputStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
            <item name="boxStrokeWidth">2dp</item>
            <item name="hintTextColor">@color/colorAccent</item>
            <item name="boxStrokeColor">@android:color/white</item>
            <item name="android:colorAccent">@color/colorAccent</item>
            <item name="android:textColorHint">@color/colorAccent</item>
        </style>
Run Code Online (Sandbox Code Playgroud)

错误 : Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

我们不能这样做而不是覆盖整个应用程序/活动主题吗?我想要的只是在特定的片段中使用它。

android android-theme material-design material-components-android

1
推荐指数
1
解决办法
2240
查看次数

如何更改材质日期选择器对话框的按钮颜色

我正在使用 Material 组件创建 DatePicker。据我了解,colorPrimary用于确定对话框顶部部分的颜色,以及按钮上文本的颜色,特别是CANCELOK

浏览文档,我似乎找不到一种方法来更改底部按钮的颜色?可以这样做吗?

当前代码:

<style name="ThemeOverlay.App.DatePicker" parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorOnPrimary">@android:color/white</item>
    <item name="shapeAppearanceSmallComponent">@style/ShapeAppearance.App.SmallComponent</item>
    <item name="shapeAppearanceMediumComponent">@style/ShapeAppearance.App.MediumComponent
    </item>
    <item name="materialCalendarHeaderTitle">@style/MyHeaderTitle</item>
    <item name="colorOnPrimarySurface">@android:color/white</item>
</style>

<style name="MyHeaderTitle" parent="Widget.MaterialComponents.MaterialCalendar.HeaderTitle">
    <item name="android:textColor">@android:color/white</item>
</style>

<style name="ThemeMaterialCalendarTextButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush">
    <item name="android:textColor">@android:color/white</item>
    <item name="iconTint">@android:color/white</item>
</style>

<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
    <item name="android:textSize">24sp</item>
    <item name="cornerSize">16dp</item>
</style>

<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
    <item name="android:textSize">30sp</item>
    <item name="cornerSize">16dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的对话

android android-datepicker material-components-android

1
推荐指数
1
解决办法
3512
查看次数

Material3 MaterialToolbar 禁用滚动着色

我正在将我的应用程序迁移到Theme.Material3.*,发现MaterialToolbar一旦某些内容在其下方滚动,它就会以某种强调色突出显示。请参阅下面我提到的动画:

屏幕录制

但是,我不希望这种效果出现在我的应用程序中。但在阅读MaterialToolbar 文档时,似乎没有办法禁用或修改它,这让我很恼火。我在这里缺少什么?

重现行为的最小 XML 布局(以及使用Material3 主题):

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:liftOnScroll="true">

        <com.google.android.material.appbar.MaterialToolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:titleCentered="true"
            app:title="Welcome"
            app:layout_scrollFlags="noScroll" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
   
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lorem ipsum dolor sit amet..." />

    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助。

android material-design android-toolbar material-components-android

1
推荐指数
1
解决办法
2250
查看次数