Is there a way to put custom_view.xml in a Button instead of the title? I want the title of my button to have 2 different strings, both using different fonts. I figure the only way to do this is to have a custom view inside of my button?
EDIT
I need to derive from the Button component to have the ripple effect when I click on the button. I don't want to use a FrameLayout with a touch listener.
EDIT 2
Would there be any way to get the shadow/border effect of a button too? I pretty much want to make it look/feel like a natural Android button, with the same look/feel when clicked, but with a custom view inside it.
You can just take the style of the button and apply it to any ViewGroup. This takes care of most properties (padding, minHeight, background drawable, ripple drawable, elevation when pressed etc.).
For example to make a simple colored button with an icon (style for TextView was changed to match the button style as well):
<LinearLayout
android:id="@+id/buttonViewGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
style="@style/Widget.AppCompat.Button.Colored">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_icon_test"/>
<TextView
style="@style/TextAppearance.AppCompat.Widget.Button.Colored"
android:text="Hallo world!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Then you are free to set any OnClickListener to LinearLayout and you're set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With