小编Ser*_*rov的帖子

如何更改主题中的材质按钮禁用状态背景颜色?

我在我的 android 项目中使用材料设计组件。

我的问题是我无法更改材质按钮的禁用背景颜色(https://material.io/develop/android/components/material-button/)。

我想在我的主题中更改DISABLED颜色,但我不知道如何做到这一点。

我尝试查看Widget.MaterialComponents.Button样式,发现它具有"backgroundTint"属性:

<item name="backgroundTint">@color/mtrl_btn_bg_color_selector</item>
Run Code Online (Sandbox Code Playgroud)

但它没有禁用状态样式,见下文:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="?attr/colorPrimary" android:state_enabled="true"/>
  <item android:alpha="0.12" android:color="?attr/colorOnSurface"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

我总是可以自己添加它,但是禁用按钮的初始灰色来自哪里?

在我的主题中全局更改此颜色的最佳方法是什么?

PS我正在使用Theme.MaterialComponents.NoActionBar主题。

谢谢!

android android-button material-design material-components material-components-android

8
推荐指数
2
解决办法
4762
查看次数

ListenableWorker 不会删除通知图标

我正在使用 ListenableWorker 来执行后台任务。我也希望操作系统意识到我的服务重要性,所以我打电话

 setForegroundAsync(new ForegroundInfo(WorkerConstants.NOTIFICATION_FOREGROUND_ID,
 builder.build()));
Run Code Online (Sandbox Code Playgroud)

正如谷歌文档中所建议的那样。

但是当我的服务停止或取消时,我仍然可以看到前台服务通知并且我无法删除它。

此外,我在此通知中添加了取消按钮,但它什么也没做,我无法关闭它:

PendingIntent intent = WorkManager.getInstance(getApplicationContext())
                            .createCancelPendingIntent(getId());
                    builder.addAction(R.drawable.ic_redesign_exit,"Stop",intent);
Run Code Online (Sandbox Code Playgroud)

有什么建议?

android android-notifications android-workmanager

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