I'm developing and Android app. I have a main menu with lots of imagebuttons, each of which takes the user to a new view on click.
The problem I'm having is that surrounding each icon is a tinted rectangle that changes to a light blue colour when tapped. How do I remove this transparent square in the .xml layout file?
Many thanks in advance,
they probably have the default background from the android system. to remove that, define a transparent color
<color name="transparent">#00000000</color>
and then use it as background in your buttons
<ImageButton android:src="#drawable/button"
android:background="#color/transparent"/>
I think it will work the way you want
You could always use the framework's
android:background="#android:color/transparent"
But for what you are trying to archive this is the better solution:
android:background="#null"
I know theres now rectangle or colour, when you use your own buttons.. create, implement and use them, then you wont have the rectangle
Related
I've got an ImageButton:
and I want to make the transparent parts of the image into another color, while leaving the background white. Is there a way to do that in xml (or code)?
I've tried:
android:background="#color/colorPrimary"
and
android:backgroundTint="#color/colorPrimary"
but this changes the whole background to the different color and not the transparent part. It leaves the transparent part white.
use android:tint="#color/colorPrimary"
Currently I have a button that looks like this:
What I want to do is to be able to replace the text with this vector drawable but keep the blue rectangle background:
I looked into doing this but I cannot seem to get it right.
I tried the following combination:
<Button
android:id="#+id/deletebutton"
android:layout_width="0dp"
android:layout_height="50dp"
android:src="#drawable/deletebtn24dp"
android:backgroundTint="#color/primaryButtonColor"
android:layout_weight="1"/>
However that just led to a blank blue button with no drawable. What can I do so the drawable replaces the text?
Also I would like to support API levels start at 16+.
You have to use app:srcCompat="#drawable/deletebtn24dp" instead of android:src="#drawable/deletebtn24dp". Using an ImageButton might also be better than using a straight Button.
I've been looking for this for a while but can't really figure out any clean way to do it.
I'm developing an app with some buttons, mostly defined like this:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:contentDescription="#null"
android:src="#drawable/btn1" />
There's a onTouchListener that changes the button alpha with setAlpha(0.5f), but it also changes the background alpha, which is not what I need. I'd like to make it look darker, not trasparent.
I've seen this question: Android Graphics: Changing the alpha of just an image (not the background), and the solution actually works, but it doesn't sound good for me to create a FrameLayout for every button in my app.
Given the fact that the background is a flat color I thought there would be a simpler solution such as color blending or something like that, but really couldn't find it anywhere.
SOLUTION
Just found out this post: http://tech.chitgoks.com/2011/04/17/android-change-imagebutton-tint-to-simulate-button-pressed/
The solution is as simple as:
button.setColorFilter(Color.argb(150,0,0,0));
You can get image drawable using getDrawable() method and try to change its alpha.
Pretty much what the title says. I'm wanting the user to have the choice to customize the boarder of a 9 drawable I have. Is something like that possible or do I need to use a different method? Right now, I think it won't work and it will mess up the 9 patch.
Can you post a picture of your 9-patch? It might be possible to extract parts of it to another type of drawable, then layer the customizable part (drawn with user defined color) under the fixed portions using a layer-list.
[Update] Based on the pic you posted, I'd trash the layer list idea, but we can still work something out. The idea would be to remove the colored border and internal dark background from the 9-patch entirely (fill that area in with the shadow color and opacity). Then nest 3 layouts in each other. The first would use the 9-patch as a background. The second would use the user-defined color as a background. The third would use your panel color as a background. The 9-patch would provide the proper margins to position the second (user-color) layout, and then you'd just add a layout_margin attribute to the second panel to position the inner most layout a few dps in.
<LinearLayout
android:id="#+id/PanelOuter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/shadow_nine_patch">
<LinearLayout
android:id="#+id/PanelUserBorder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/custom_border_width"
android:background="#color/dialog_border_color_default">
<LinearLayout
android:id="#+id/PanelContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/custom_dialog_content_margin"
android:background="#color/dialog_inner_color">
</LinearLayout>
</LinearLayout>
</LinearLayout>
Of course, you'd be responsible for finding the PanelUserBorder view in code and calling setBackgroundColor() with the proper user-defined color.
maybe you could tint it by putting a 50% transparent view overtop the button.
after thinking about it i thought maybe you could transform the color by bitmap:
How to change Bitmap image color in android?
The default progress wheel on Android doesn't display well when the background is white, it's barely visible. How can I fix this?
If you look at the built in styles.xml file and poke around the platform's built in drawables, it turns out the solution is pretty simple. You can use the "style" attribute to use the inverse progress bar:
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="40dip"
android:layout_height="40dip"
android:padding="6dp"
android:indeterminate="true"
style="?android:attr/progressBarStyleInverse"
/>
Be sure if you have a white background to set the theme in your manifest to #android:style/Theme.Light. This provides resources for all of the widgets to go with a light background.
I dont think there is way to fix this since the progressbar is sdk dependant. orange on 1.5, white on 1.6 etc... green on some devices, etc etc...
Your would have to implement/override it with your own graphics to change it.
I had the similar problem, i solved it by setting a constrasting background on the progressbar. (50% transparent black)
Here is similar issue using the horisontal progressbar implementing a custom color:
How to change progress bar's progress color in Android
The circular is abit diffrent i think, but probably not impossible ;-)