我正在尝试创建一个无边界按钮,但是我还有许多其他样式的按钮,我想通过将代码嵌入我的style.xml文件来设计无边界的按钮。
我发现的一种方式是:通过使用样式="?Android:atter/borderlessbuttonStyle"中的"在我的布局文件中"。
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
style="?android:attr/borderlessButtonStyle" />
,但我想在style.xml中实现这一目标,我不知道什么值是' ________ take?
您可以通过制作扩展默认按钮类的自定义按钮类来执行此操作,并在各处使用此类,第二可能的解决方案是使用
如果选择或未选择,则应使用toggle按钮https://developer.android.com/Reference/reference/android/widget/togglebutton.html
请注意,仍然有4个州
您在这样的选择中定义它们
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/likeactivepressed" />
<item android:state_pressed="true" android:drawable="@drawable/likeinitialpressed"/>
<item android:state_checked="true" android:drawable="@drawable/likeon"/>
<item android:drawable="@drawable/likeinitial"/>
</selector>
然后在按钮中定义它
android:background="@drawable/like_button"
我认为这就是您要寻找的。
<style name="style_name" parent="@style/Widget.AppCompat.Button.Borderless">
<!-- your style -->
</style>
在这里尝试一下,另一个
android:background="?android:attr/selectableItemBackground"