android-button
How to change android button text color globally in theme
<style name=”AppTheme.Base” parent=”Theme.AppCompat.Light.DarkActionBar”> <item name=”android:textColor”>#yourcolor</item> <item name=”android:buttonStyle”>@style/ButtonColor</item> <item name=”colorButtonNormal”>@color/buttonColor</item> </style> <style name=”ButtonColor” parent=”@android:style/Widget.Button”> <item name=”android:textColor”>@color/yourcolor</item> </style> android:textColor This should help you change the text color globally.
Alignment issues with two-line button
A horizontal LinearLayout aligns the baselines of all its child controls by default. So the first line of text in your multi-line button is vertically aligned with the single line of text in the other buttons. To disable this behaviour, set android:baselineAligned=”false” on the LinearLayout.
Make an Android button change background on click through XML
To change the image by using code: public void onClick(View v) { if(v.id == R.id.button_id) { ButtonName.setImageResource(R.drawable.ImageName); } } Or, using an XML file: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_pressed=”true” android:drawable=”@drawable/login_selected” /> <!– pressed –> <item android:state_focused=”true” android:drawable=”@drawable/login_mouse_over” /> <!– focused –> <item android:drawable=”@drawable/login” /> <!– default –> </selector> In OnClick, just add this … Read more
Android : Decreasing size of the Button
It’s been almost a year since the question was asked. But I faced the problem now and got a solution. 🙂 May be it will help someone. You can achieve this by setting android:minHeight=”0dp” for the Button widget. And I guess this behavior is because there is some default value (may be a 48dp) set … Read more
How to create a circular outlined Material Button in Android?
You can use the app:shapeAppearanceOverlay attribute to define the corner size. You can use the 50% value. <com.google.android.material.button.MaterialButton android:layout_width=”50dp” android:layout_height=”50dp” style=”@style/Widget.MaterialComponents.Button.OutlinedButton.Icon” app:icon=”@drawable/ic_add_24px” app:iconSize=”24dp” app:iconGravity=”textStart” android:padding=”0dp” app:iconPadding=”0dp” android:insetLeft=”0dp” android:insetTop=”0dp” android:insetRight=”0dp” android:insetBottom=”0dp” app:shapeAppearanceOverlay=”@style/ShapeAppearanceOverlay.MyApp.Button.Circle” /> with: <style name=”ShapeAppearanceOverlay.MyApp.Button.Circle” parent=””> <item name=”cornerFamily”>rounded</item> <item name=”cornerSize”>50%</item> </style> or with the style=”@style/Widget.MaterialComponents.Button.Icon” It requires at least the version 1.1.0. With jetpack compose … Read more