失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Android Material Design按钮样式

Android Material Design按钮样式

时间:2023-09-12 01:06:40

相关推荐

Android Material Design按钮样式

本文翻译自:Android Material Design Button Styles

I'm confused on button styles for material design.我对材质设计的按钮样式感到困惑。I'd like to get colorful raised buttons like in the attached link., like the "force stop" and "uninstall" buttons seen under the usage section.我想获得彩色的凸起按钮,如附件链接中所示。例如,在“使用情况”部分下看到的“强制停止”和“卸载”按钮。Are there available styles or do I need to define them?是否有可用的样式或需要定义它们?

/design/spec/components/buttons.html#buttons-usage/design/spec/components/buttons.html#buttons-usage

I couldn't find the default button styles.我找不到默认的按钮样式。

Example:例:

<Button style="@style/PrimaryButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Calculate"android:id="@+id/button3"android:layout_below="@+id/editText5"android:layout_alignEnd="@+id/editText5"android:enabled="true" />

If I try to change the background color of the button by adding如果我尝试通过添加来更改按钮的背景色

android:background="@color/primary"

all of the styles go away, such as the touch animation, shadow, rounded corner, etc.所有样式都会消失,例如触摸动画,阴影,圆角等。

#1楼

参考:/question/1mXzD/Android-Material-Design按钮样式

#2楼

you can give aviation to the view by adding z axis to it and can have default shadow to it.您可以通过向其添加z轴来为视图提供航空功能,并为其具有默认阴影。this feature was provided in L preview and will be available after it release.此功能在L预览中提供,并且在发布后将可用。For now you can simply add a image the gives this look for button background现在,您只需添加图像即可使按钮背景看起来像这样

#3楼

Here is how I got what I wanted.这就是我想要的方式。

First, made a button (instyles.xml):首先,制作一个按钮(在styles.xml):

<style name="Button"><item name="android:textColor">@color/white</item><item name="android:padding">0dp</item><item name="android:minWidth">88dp</item><item name="android:minHeight">36dp</item><item name="android:layout_margin">3dp</item><item name="android:elevation">1dp</item><item name="android:translationZ">1dp</item><item name="android:background">@drawable/primary_round</item></style>

The ripple and background for the button, as a drawableprimary_round.xml:按钮的波纹和背景,作为可绘制的primary_round.xml

<ripple xmlns:android="/apk/res/android"android:color="@color/primary_600"><item><shape xmlns:android="/apk/res/android"><corners android:radius="1dp" /><solid android:color="@color/primary" /></shape></item></ripple>

This added the ripple effect I was looking for.这增加了我一直在寻找的涟漪效应。

#4楼

If I understand you correctly, you want to do something like this:如果我对您的理解正确,那么您想要执行以下操作:

In such case, it should be just enough to use:在这种情况下,使用它就足够了:

<item name="android:colorButtonNormal">#2196f3</item>

Or for API less than 21:或对于少于21的API:

<item name="colorButtonNormal">#2196f3</item>

In addition to Using Material Theme Tutorial .除了使用Material Theme教程 。

Animated variant is here .动画变体在这里 。

#5楼

Here is a sample that will help in applying button style consistently across your app.这是一个示例,有助于在应用程序中一致地应用按钮样式。

Here is a sample Theme I used with the specific styles..这是我与特定样式一起使用的示例主题。

<style name="MyTheme" parent="@style/Theme.AppCompat.Light"><item name="colorPrimary">@color/primary</item><item name="colorPrimaryDark">@color/primary_dark</item><item name="colorAccent">@color/accent</item><item name="android:buttonStyle">@style/ButtonAppTheme</item></style><style name="ButtonAppTheme" parent="android:Widget.Material.Button"><item name="android:background">@drawable/material_button</item></style>

This is how I defined the button shape & effects inside res/drawable-v21 folder...这就是我在res / drawable-v21文件夹中定义按钮形状和效果的方式...

<?xml version="1.0" encoding="utf-8"?><ripple xmlns:android="/apk/res/android"android:color="?attr/colorControlHighlight"><item><shape xmlns:android="/apk/res/android"><corners android:radius="2dp" /> <solid android:color="@color/primary" /></shape></item></ripple>

2dp corners are to keep it consistent with Material theme.2dp角落将使其与Material主题保持一致。

#6楼

I've just created an android library, that allows you to easily modify the button color and the ripple color我刚刚创建了一个android库,可让您轻松修改按钮颜色和波纹颜色

/xgc1986/RippleButton/xgc1986/RippleButton

<com.xgc1986.ripplebutton.widget.RippleButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/btn"android:text="Android button modified in layout"android:textColor="@android:color/white"app:buttonColor="@android:color/black"app:rippleColor="@android:color/white"/>

You don't need to create an style for every button you want wit a different color, allowing you to customize the colors randomly您无需为要使用不同颜色的每个按钮创建样式,即可随意自定义颜色

如果觉得《Android Material Design按钮样式》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。