Ashutosh Sharma
Ashutosh Sharma

Reputation: 128

How to create borderless button using style from style.xml file (along with all other styles)

I am trying to create a borderless button, but I also have many other styles for my button and I want to design button borderless by embedding code into my style.xml file.

One way I found was: By using style="?android:attr/borderlessButtonStyle" in my layout file.

<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" />

But I want to make this happen in style.xml and I don't know what values does ' _______ take?

Upvotes: 2

Views: 1640

Answers (3)

Faisal Debouni
Faisal Debouni

Reputation: 21

I think this is what you're looking for.

<style name="style_name" parent="@style/Widget.AppCompat.Button.Borderless">
    <!-- your style -->
</style>

Upvotes: 1

Akhilesh V S
Akhilesh V S

Reputation: 71

Try this here and another

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

Upvotes: 0

Sandip Savaliya
Sandip Savaliya

Reputation: 784

You can do this by making Custom Button class which extend default Button class, and use this class everywhere, and second possible solution is use

If it's selected or not selected you should use a toggle button https://developer.android.com/reference/android/widget/ToggleButton.html

Be aware that there are still 4 states for that

You define them in a selector like this

<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>

Then define it in your button like this

android:background="@drawable/like_button"

Upvotes: 2

Related Questions