如何正确的Andr​​oid风格的材料按钮如何正确、按钮、风格、材料

2023-09-06 07:03:51 作者:弄潮

我后,我的例子平面按钮走,但真正的问题适用于所有的按钮。为什么它似乎很难找到的正确方法风格材料按钮文档中的机器人。

I am going after flat buttons for my example, but the question really applies to all buttons. Why does it seem so hard to find documentation on the proper way to style material buttons in android.

我有我,直到我能得到它的工作搞砸围绕以下。感觉就像一个黑客,所以我不知道如果这是真的做了正确的方式。

I have the following which I messed around with until I could get it to work. Felt like a hack so I am not sure if this is really the right way to do it.

    <Button
        android:id="@+id/apply"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/md_cyan_A700"
        android:text="Cancel"/>

所以我用'borderlessButtonStyle撒气按钮。我只好到文字颜色更改为材质颜色我想为按钮。

So I used 'borderlessButtonStyle' to get a flat button. And I had to change the textColor to the material color I wanted for the button.

最重要的事情是我觉得像动画是错了,当我不喜欢这样。我不明白整个按钮一个很好的涟漪,而是我得到一个灰色圆圈的基础上,我点击。如果我点击边缘附近的圆圈被切断。只是觉得错了。

Biggest thing is I feel like the animations are wrong when I do it like this. I don't get a nice ripple across the button, instead I get a grey circle based on where I click. And the circle gets cut off if I click near edges. Just feels wrong.

同样的颜色看起来正确的,但我不知道这是正确的方式做到这一点。为什么会出现不适合的材料按钮开箱即用'平'的风格。这是一个普通的材料的风格。

Again the color looks right but I am not sure this is the 'correct' way to do this. Why is there not 'flat' style for a material button out of the box. It is a regular material style.

推荐答案

地址:

android:background="?android:attr/selectableItemBackgroundBorderless"