- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
安卓6.0
安卓工作室 3.6
在我的 fragment 中,当单击按钮时,我会像这样“即时”更改样式:
bluetoothPageViewModel.isDisableModeLiveData().observe(this, Observer {
dataBinding.buttonStartSearchBluetooth.setTextAppearance(
R.style.buttonDisableStyle
);
})
这里的xml布局:
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonStartSearchBluetooth"
style="@style/buttonStyle"
android:layout_width="0dp"
android:layout_height="@dimen/button_height"
android:layout_margin="@dimen/button_margin"
android:onClick="onClickButtonStartSearch"
android:text="@string/start_search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
这里是 styles.xml
<style name="buttonDisableStyle" parent="@style/Widget.MaterialComponents.Button">
<item name="android:textColor">@color/default_button_textColor</item>
<item name="backgroundTint">@color/button_bg_color</item>
<item name="android:enabled">false</item>
<item name="android:clickable">false</item>
<item name="android:textAppearance">@style/byttonTexAppearanceStyle</item>
</style>
<style name="byttonTexAppearanceStyle" parent="@style/TextAppearance.MaterialComponents.Button">
<item name="android:textSize">18sp</item>
<item name="android:textAllCaps">true</item>
</style>
但是在调用 setTextAppearance
之后我仍然可以点击按钮。为什么?
最佳答案
setTextAppearance
只关心 View 文本的样式。检查official doc查看受 setTextAppearance
影响的支持属性。
您必须手动处理其他属性,检查以下内容:
bluetoothPageViewModel.isDisableModeLiveData().observe(this, Observer {
dataBinding.buttonStartSearchBluetooth.setTextAppearance(
R.style.byttonTexAppearanceStyle
);
dataBinding.buttonStartSearchBluetooth.setEnabled(false);
dataBinding.buttonStartSearchBluetooth.setClickable(false);
dataBinding.buttonStartSearchBluetooth.setBackgroundTintList(
ContextCompat.getColorStateList(this, R.color.button_bg_color))
);
})
<style name="byttonTexAppearanceStyle" parent="@style/TextAppearance.MaterialComponents.Button">
<item name="android:textSize">18sp</item>
<item name="android:textAllCaps">true</item>
<item name="android:textColor">@color/default_button_textColor</item>
</style>
关于android - setTextAppearance - 尝试禁用点击时不适用于 MaterialButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58589889/
我在布局中有四个 MaterialButton,我想在按下其中一个按钮时更改所有按钮的颜色。其中两个带有一种颜色,另外两个带有另一种颜色。我该怎么做? 最佳答案 只需调用 setState() 并使用
安卓工作室 3.3.2 classpath 'com.android.tools.build:gradle:3.3.2' 在我的新 Android 项目中,我想使用新的 android Materia
我正在尝试使用 MaterialButton,但它无法正常工作。我的 androidx 依赖 implementation 'androidx.appcompat:appcompat:1.0.2' i
我正在尝试创建一个从 MaterialButton 扩展的自定义 View 并在代码中应用样式,因此我不需要在 xml 中执行此操作。 class CustomRedButton @JvmOverlo
我想以编程方式创建一个按钮,如此处的设计指南中所定义:https://material.io/design/components/buttons.html#outlined-button ,看起来像这
我正在这样做 但是图标显示在文本的左侧,图标重力对图标位置没有影响。 在普通按钮中,我们曾经使用 drawableRight 实现相同的效果,但这里没有找到方法。 最佳答案 app:icon="@d
我想将图标放在 materialButton 的顶部,如下所示: 但是我在 MaterialButton 中找不到任何属性来设置应用程序的重力:图标到顶部。我只能将它设置为开始或结束。有没有什么方法可
我正在尝试使用一个 Material 按钮,我想要在最左边有一个图标,然后在中间有一些文本。但是,例如,当我将图标放在左侧时,我可以清楚地看到文本被推到右侧。有什么办法可以避免这种情况吗?我希望文本居
我正在使用最新版本的 com.google.android.material:material 库(即 1.1.0-alpha03),并且我有一个 MaterialButton 使用图标定义,无文本,
这是按钮的代码 这是尝试在按钮中添加描边时的图像 Image With added stroke in button 下面是没有笔画宽度的代码 Image without Stroke 我尝试了不
您好,我遇到了在 Android 上对齐 Material 按钮中的图标的问题。我有 match_parent 宽度、文本和文本旁边的图标的按钮。我想将图标 8dp 左对齐到文本,我尝试通过 com.
安卓6.0 安卓工作室 3.6 在我的 fragment 中,当单击按钮时,我会像这样“即时”更改样式: bluetoothPageViewModel.isDisableModeLiveData(
参见: 代码: 样式.xml rounded 20dp 为了确认 Material 按钮包含完整空间,我将
我正在尝试构建一个带有边框按钮的布局,如下所示(预期行为)。从 Material design 文档中,我了解到 Outlined Material Button 似乎非常适合我的目的。我在我的布局中
我们正在使用 Material Components 1.0.0,并希望在整个应用程序中更改 MaterialButton 的样式。我们创建了自己的样式,扩展了组件库中的样式。现在我们有类似的东西:
我正在使用 supportLibrary = "28.0.0-beta01" 版本。 这是我在 .xml 文件中的代码: 到位于按钮左侧的可绘制对象的代码图标。我想将按钮设置为中心。我想达到这个结果
我正在使用支持库中的 Materialbutton。我希望图标位于文本的右侧?我似乎找不到如何去做。感谢任何帮助 最佳答案 您可以使用 app:iconGravity 属性。 使用 app:iconG
我这辈子都想不通按钮宽度的问题。我不知道按钮当前的宽度是多少,但我可以告诉你,当我告诉它时它并没有减少。它保持完全相同,并且在增加 minWidth 值时甚至不会增加。 Material( chi
我尝试向 MaterialButton 添加一个简单的 BadgeDrawable,但没有显示徽章。 我已经在我的 build.gradle 中尝试了以下版本: 'com.google.android
如果我设置 Theme.MaterialComponents.Light 作为我的主题,如果我在 xml 布局中使用这两个按钮,它们之间会有什么区别吗? 正如我所看到的,它们都表现为 Materi
我是一名优秀的程序员,十分优秀!