This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
ImageButton doesn’t highlight on click with Transparent background
I have made a custom bar where I have buttons with the attribute
android:background="#android:color/transparent"
My problem is that when I click on the buttons the click effect does not trigger(in this case the button should become and blue and fade back in its original color -transparent here-).
How do I enable it or just simulate the effect? Any ideas?
Seems transparent is a bad option. Better have
style="?android:attr/borderlessButtonStyle"
same effect, without needing to go through creating another custom xmls
You need to use selector check: http://developer.android.com/guide/topics/ui/controls/button.html under "Custom background"
Related
I want to open a Dialouge as soon as i press an emoji button, how could I add such a button in Android Studio, is there a possible library to do this? also possibly add ripple effect etc. I want the button to just be an emoji, meaning that there must not be any emojis as text on button (only if it's possible to have the moji occupy the entire view).
You can find the emoji you want from here:
https://apps.timwhitlock.info/emoji/tables/unicode
And replace 'U+' to '0x'
U+1F60A to 0x1F60A
int unicode = 0x1F60A;
emojiButton.setText(new String(Character.toChars(unicode)));
About the ripple effect:
If you use android.widget.Button, it already has ripple effect by default.
But if you use anything else, you need this:
android:background="?android:attr/selectableItemBackground"
or if you want circle ripple effect:
android:background="?android:attr/actionBarItemBackground"
How to disable ripple effect on long press of a button in lollipop?
When using sherlock long press of a button is not showing ripple effect but when i use appcompat it is showing a ripple effect on click and also on long click of a button .
I do not want any ripple effect on the press of a button
If you are using MaterialButton, then set app:rippleColor:
<com.google.android.material.button.MaterialButton
...
app:rippleColor="#android:color/transparent" />
Thanks to this and this answer for their help.
If you have root, have a look at my patch here https://github.com/luv/android5_noripple
My patch simply replaces draw function in android.graphics.drawable.Ripple with a function that does nothing but returns True.
You need to fetch /system/framework/framework.jar from your phone, patch it, and push it back (you need root for this). See the link for step-by-step instructions.
I want the button to appear as though it has space in between the bottom of it's face and the canvas. Then, when clicked, it will appear as though there is no space between the button and the canvas. I know I can style the button with xml to give it those 2 looks but I don't know how to do the elevated look.
My question is how would one go about doing this?
Easiest approach to this is creating 2 background images, each fitting the state you want, then you can either set the backgrounds according the button's state, or change the backgrounds by setting an onTouchListener to the button.
This question already has answers here:
Actionbar background is not being changed
(2 answers)
Closed 8 years ago.
In my application, I am using actionbarsherlock. I use
getSupportActionBar().setBackgroundDrwable(R.drawable.test).
It works fine, the color is showed as expected, however when I go to another activity and go back to the main activity. The bar color is changed to black (in my program, I dont set black for the backgrounddrawble and just call setSupportAction().setBackgroundDrawable in onStart()). However, if I change the code to
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff550000)));
The app works fine. When I click on back button, the color is set to 0xff55000 which is expected.
I will suggest not to use the color code directly this way while you are trying to set the color programmatically. It will not take it. just try out this way..
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mContext.getResources().getColor(Color.BLACK)));
Hope it will work for you.
It doesn't work well for me either, specially if I use with the navigation drawer toggle list. In my case, if i don't use the toggle, the background goes white during a second and then load the background drawable. If I use the toggle, the background remains white.
I had to use a custom view to achive the effect I wanted to get instead of changing the background.
I have almost the same issue, it happens that calling getActionBar().setBackgroundDrawable twice does not work.
If I only call it only once in the onCreate is works. If I put the code in the onResume, it works for the first onResume, but it is set to grey for any other onResume
I am using a button with my own back ground color in android and that button is not getting focus what is the problem?
Buttons normally will not have focus by touch. Also focus depends on the background.
So, check the background - it needs to be of type drawable with multiple states or you need to make a gradient. Check Standard Android Button with a different color