android android-textinputlayout material-components material-components-android
fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(PrivateDealActivity.this, R.color.colorWhite)));
Run Code Online (Sandbox Code Playgroud)
这是行不通的。如何更改浮动操作按钮的背景颜色
android material-design floating-action-button material-components material-components-android
如何使用新的材质组件从按钮中删除等宽字体?
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_register"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:fontFamily="@font/lato"
app:backgroundTint="@color/white"
android:textColor="?colorPrimary"
android:text="Open Register Screen" />
Run Code Online (Sandbox Code Playgroud)
此图显示了我要消除的差异:

如何使用TextInputLayout实现居中的新OutlinedBox样式?
当前行为:
Run Code Online (Sandbox Code Playgroud)<android.support.design.widget.TextInputLayout android:id="@+id/textInputLayout2" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="left" > <android.support.design.widget.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="left" android:hint="hint" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@+id/textInputLayout" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" > <android.support.design.widget.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:hint="hint2" /> </android.support.design.widget.TextInputLayout>
我用com.android.support:design:28.0.0。
有什么想法可以实现以外观为中心的TextInputEditText?
android android-support-library android-textinputlayout material-components material-components-android
我正在使用BottomAppBar来自谷歌的这样的:
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/vNavigationBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
Run Code Online (Sandbox Code Playgroud)
自定义底栏是平的,我需要在底栏上添加圆角(图像示例如下)
我该怎么做才能以这种方式工作?
xml android android-layout android-bottomappbar material-components-android
MaterialCardView 的每个角半径是否可以有不同的值?如果是这样怎么办?
我尝试了类似下面的代码,但似乎没有任何效果
float radius = getContext().getResources().getDimension(R.dimen.default_corner_radius);
ShapePathModel leftShapePathModel = new ShapePathModel();
leftShapePathModel.setTopLeftCorner(new RoundedCornerTreatment(radius));
leftShapePathModel.setTopRightCorner(new RoundedCornerTreatment(radius));
MaterialShapeDrawable bg = new MaterialShapeDrawable(leftShapePathModel);
container.setBackground(bg);
Run Code Online (Sandbox Code Playgroud)
容器在哪里
@BindView(R.id.container) MaterialCardView container;
Run Code Online (Sandbox Code Playgroud) android android-layout android-cardview material-components material-components-android
我使用的是该com.google.android.material:material库的最新版本(即1.1.0-alpha03),并且有一个MaterialButton带有图标且没有文本的定义,如下所示:
我希望MaterialButton将其渲染为一个正方形,其中图标居中放置,但MaterialButton渲染如下:
如果我将iconGravity值更改为"textStart",MaterialButton则呈现如下:
这对图标的位置略有改善,但是图标仍然偏离中心一点。如果我改变了insetLeft,insetRight,insetTop和insetBottom值0dp将MaterialButton呈现如下:
这是对按钮形状的改进,但图标仍偏离中心。
有人知道我是否可以做进一步的事情来将图标居中MaterialButton?
我正在使用 Material Components 来创建 Choice 芯片。我遵循了https://material.io/develop/android/components/chip/文档。有足够的东西可以用 XML 创建芯片,但不知道如何以编程方式创建选择芯片。
我使用以下代码动态创建芯片,但默认情况下它创建动作芯片。
val chip = Chip(activity)
chip.text = ("Chip 1")
chipGpRow.addView(chip)
Run Code Online (Sandbox Code Playgroud) android android-chips material-components material-components-android
是否有选项可以MaterialButtonToggleGroup在使用时选择所需的按钮app:singleSelection="true"?
当单击不同的按钮工作正常(所有其他按钮都被取消选择),但是当您单击同一个(已选择)按钮时,它会自行取消选择它,我想保持选中状态。
我的例子:
<com.google.android.material.button.MaterialButtonToggleGroup
android:layout_width="wrap"
android:layout_height="wrap_content"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="@+id/filterA"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/filterB"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/filterC"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"/>
</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud) android android-button android-togglebutton material-components material-components-android
根据文档
支持旧版本平台上兼容功能的按钮,包括:
允许通过 ViewCompat 中的背景色调方法对其背景进行动态色调。允许使用 R.attr.backgroundTint 和 R.attr.backgroundTintMode 设置背景色调。当您在布局中使用 Button 并且顶级活动/对话框由 appcompat 提供时,这将自动使用。您应该只需要在编写自定义视图时手动使用此类。
现在,这让我假设以下两个按钮在高级设备上看起来完全相同。
<androidx.appcompat.widget.AppCompatButton
android:text="AppCompatButton"
android:id="@+id/appcompatbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_below="@id/appcompatbutton"
android:id="@+id/button"
android:layout_width="wrap_content"
android:text="Button"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)
然而,这是它的实际外观:
我在以下模拟器上运行了这个:Galaxy Nexus,API:28 (720 x 1280 xhdpi)
当我像这样在 appTheme 中应用 buttonStyle 时:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="buttonStyle">@style/Widget.MaterialComponents.Button</item>
</style>
Run Code Online (Sandbox Code Playgroud)
它改变了 AppCompatButton 而不是像这样的普通按钮:(注意圆角边缘的细微差别)
我还尝试创建一个既继承自 android.widget.Button 又继承自 androidx.appcompat.widget.AppCompatButton 的自定义按钮,这两个按钮显示的行为与在 xml 中使用 AppCompatButton 的行为相同。所以感觉唯一的异常值是 XML 中的 Button。
问题 1: …
android android-button material-design material-components-android androidx