Posts

Showing posts with the label Button

Android Button With Rounded Corners, Ripple Effect And No Shadow

Answer : I finally solved it with below code. This achieve rounded corners for button. Also, for Android Version >= V21, it uses ripple effect. For earlier Android version, button color changes when it is clicked, based on android:state_pressed, android:state_focused , etc. In layout xml file: <Button style="?android:attr/borderlessButtonStyle" android:id="@+id/buy_button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:gravity="center" android:background="@drawable/green_trading_button_effect" android:textColor="@android:color/white" android:text="BUY" /> For button onclick ripple effect (Android >= v21) : drawable-v21/green_trading_button_effect.xml <?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android...

Android: Combining Text & Image On A Button Or ImageButton

Answer : For users who just want to put Background, Icon-Image and Text in one Button from different files: Set on a Button background, drawableTop/Bottom/Rigth/Left and padding attributes. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/home_btn_test" android:drawableTop="@drawable/home_icon_test" android:textColor="#FFFFFF" android:id="@+id/ButtonTest" android:paddingTop="32sp" android:drawablePadding="-15sp" android:text="this is text"></Button> For more sophisticated arrangement you also can use RelativeLayout (or any other layout) and make it clickable. Tutorial: Great tutorial that covers both cases: http://izvornikod.com/Blog/tabid/82/EntryId/8/Creating-Android-button-with-image-and-text-using-relative-layout.aspx There's a mu...

Android Button TextAppearance

Answer : The values of attributes defined using textAppearance are applied before the values of attributes in a style. A Button is a TextView with a style applied, and the default style of a Button will override your textAppearance (Android 2.3 for example will set it to ?android:attr/textAppearanceSmallInverse) and textColor. textAppearance excepts styles as values, android:textAppearance="@style/login_button_text_appearance" is the normally correct way to set a textAppearance, but not for a Button : If you're changing the text colour of a Button , you should also enforce a custom background image because if you don't, one device will use a dark background image (motorola defy) and another will use a light image (htc desire) which may make the text difficult to read. I think you should use : style = "@style/login_button_text_appearance" instead of: android:textAppearance="@style/login_button_text_appearance" The android:textAppe...

Android Scale Button On Touch

Answer : Try the following: @Override public boolean onTouch(View v, MotionEvent motionEvent) { int action = motionEvent.getAction(); if (action == MotionEvent.ACTION_DOWN) { v.animate().scaleXBy(100f).setDuration(5000).start(); v.animate().scaleYBy(100f).setDuration(5000).start(); return true; } else if (action == MotionEvent.ACTION_UP) { v.animate().cancel(); v.animate().scaleX(1f).setDuration(1000).start(); v.animate().scaleY(1f).setDuration(1000).start(); return true; } return false; } This should do the trick ;)

Css Gradient Background Button

Answer : Well, they used this in default state: background: #0079FF; background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0096FF), to(#005DFF)); background: -webkit-linear-gradient(0% 0%, 0% 100%, from(#0096FF), to(#005DFF)); background: -moz-linear-gradient(center top, #0096FF, #005DFF); For hover they have other colors of course. Just change the color for your needs.

Android: TextColor Of Disabled Button In Selector Not Showing?

Answer : You need to also create a ColorStateList for text colors identifying different states. Do the following: Create another XML file in res\color named something like text_color.xml . <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- disabled state --> <item android:state_enabled="false" android:color="#9D9FA2" /> <item android:color="#000"/> </selector> In your style.xml , put a reference to that text_color.xml file as follows: <style name="buttonStyle" parent="@android:style/Widget.Button"> <item name="android:textStyle">bold</item> <item name="android:textColor">@color/text_color</item> <item name="android:textSize">18sp</item> </style> This should resolve your issue. 1.Create a color folder ...