所以我想风格LinearLayout
看起来像一个按钮。我使用LinearLayout
,因为我使用的“字体真棒”的图标,我需要把图标的按钮里面,所以我有一个LinearLayout
,它有两个TextView
S作为孩子。一个用于图标,另一个用于文本。Android的风格查看喜欢的彩色按钮
我要的是让LinearLayout
看起来像默认样式的按钮,但在不同的颜色。在棒棒糖和更新,它也应该有连锁反应。
我设法做到这一点,通过添加一个backgroundTint
,但它只适用于棉花糖,在KitKat该按钮具有默认颜色。这里是我的代码:
布局:
<LinearLayout
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
style="@style/MyTheme.Button" >
<TextView
android:id="@+id/ic_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="@string/fa_user_plus"
android:textSize="16dp"
android:paddingRight="4dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="Register as a new user"
android:textSize="16dp" />
</LinearLayout>
风格:
<style name="MyTheme.Button" parent="@android:style/Widget.DeviceDefault.Button">
<item name="android:backgroundTint">@color/accent</item>
</style>
尝试采用了android:背景,而不是机器人的:backgroundTint – Joakim
@Joakim,消除所有的按钮风格 - 波纹和圆角。 –
也许你可以使用一个简单的按钮,图标作为背景,并将你的文本放置在你想要的layout_align中。这比布局更容易,但我不知道是否对你有用。 –