问题
I wrote custom View which draws a circle. Then I put it on relative layout. Also I put standard button there, so that they overlap. And I see that button is transparent. How to make it non transparent?

回答1:
The standard Holo themed button is partially transparent. You can either create a new button 9.png image to use in the button or create a new button by using drawable.
Here's a link on how to do the latter:
http://droidapp.co.uk/?p=309
回答2:
Set the background to @android:drawable/btn_default
to get rid of the transparency of holo theme
回答3:
you can put the button in seperate Frame Layout so that your view wont affect the button and thats my idea
回答4:
save below code as xml in drawable folder and give this xml as button background
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="0dp" android:color="#ffffff" />
<solid android:color="#000000"/>
<corners android:radius="1px"/>
<padding android:left="5dp" android:top="3dp" android:right="5dp" android:bottom="3dp" />
</shape>
Ex:
android:background="@drawable/<< your file name>>"
回答5:
I was with the same problem but with ToggleButton. A ugly but fast solution was to position a ImageView right behind the button and change its margin
s, background
and alpha
to fit the button. For example, inside a RelativeLayout:
<ImageView
android:layout_alignLeft="@+id/toggleButton"
android:layout_alignBottom="@+id/toggleButton"
android:layout_alignRight="@+id/toggleButton"
android:layout_alignTop="@+id/toggleButton"
style="@style/HackBackgroundToggleButton" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toggleButton"
... />
And, in an effort to reduce the visible hack, the extracted style:
<style name="HackBackgroundToggleButton">
<item name="android:layout_width">84dp</item>
<item name="android:layout_height">42dp</item>
<item name="android:background">#FFFFFF</item>
<item name="android:layout_marginTop">4dp</item>
<item name="android:layout_marginLeft">4dp</item>
<item name="android:layout_marginRight">4dp</item>
<item name="android:layout_marginBottom">4dp</item>
<item name="android:alpha">0.75</item>
</style>
回答6:
The holo transparency is actually built into the PNG files. So the only real way to change it is to edit the PNGs and make them non-transparent. This is actually not easy at all. You need to multiply the alpha channel of the image by 255/102. Which isn't easy!
But because I am such a genius, I found a way to do it. Basically I copied all the relevant PNGs and XMLs into their own directory structure (the buttons only have -mdpi
, -hdpi
and -xhdpi
versions). Then I ran this:
for FILE in find . -name *.png
; do mogrify -evaluate Multiply 2.5 -channel Alpha $FILE ; done
Job done! Actually it didn't quite work for the disabled buttons for some reason - I think because the centre is super-transparent, but I don't care so much about those. You'll have to use a higher value than 2.5 for those images if you want them totally non-transparent.
Anway the result is here.
来源:https://stackoverflow.com/questions/10633040/how-to-make-button-non-transparent