我想要在android.I不同的透明水平按钮使用了@机器人:彩色/透明
。但它使按钮100%透明。我需要一个70%的透明按钮。下面是XML code,我的工作的:
<的LinearLayout 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT 机器人:比重=中心 机器人:layout_weight =1> <按钮机器人:ID =@ + ID /一 机器人:文字=@字符串/ dtmf_1 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 机器人:layout_weight =1 机器人:文字颜色=@色/白>< /按钮> <按钮机器人:ID =@ + ID /两个 机器人:文字=@字符串/ dtmf_2 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 机器人:layout_weight =1 机器人:文字颜色=@色/白>< /按钮> <按钮机器人:ID =@ + ID /三 机器人:文字=@字符串/ dtmf_3 机器人:layout_width =FILL_PARENT 机器人:layout_height =FILL_PARENT 机器人:layout_weight =1 机器人:文字颜色=@色/白>< /按钮>< / LinearLayout中>
解决方案
使用XML
如果你想如果你想设置的透明设置颜色,沿着与那么你必须使用该颜色code。
的android:颜色=#66FF0000//部分透明的红机器人:阿尔法=0.25// 25%透明
用java
如果你想动态设置(JAVA的code),然后试试这个,
myButton.getBackground()setAlpha(64)。 // 25%透明
- 即.INT范围从0(完全透明)到255(完全不透明)
I want to make Buttons with different transparency levels in android.I have used "@android:color/transparent"
. But it makes the button 100% transparent. I need a 70% transparent button. Here is the XML code that I am working on:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
<Button android:id="@+id/one"
android:text="@string/dtmf_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:textColor="@color/white" ></Button>
<Button android:id="@+id/two"
android:text="@string/dtmf_2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:textColor="@color/white" ></Button>
<Button android:id="@+id/three"
android:text="@string/dtmf_3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:textColor="@color/white" ></Button>
</LinearLayout>
解决方案
Using XML
If you want to set color and along with that if you want to set transparent then you have to use that color code .
android:color="#66FF0000" // Partially transparent red
android:alpha="0.25" // 25% transparent
Using java
And if you want to set dynamically (java code)then try this,
myButton.getBackground().setAlpha(64); // 25% transparent
- i.e .INT ranges from 0 (fully transparent) to 255 (fully opaque)