按钮不透明度/透明度

use*_*504 3 xml transparency android button opacity

main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:background="@drawable/background"
        android:gravity="center"
        android:color="#66FF0000"

    >


    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/noua"
        android:textStyle="bold"
        android:textColor="#808080"
         />


    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/zece"
        android:textStyle="bold"
        android:textColor="#808080" />

    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/unspe"
        android:textStyle="bold"
        android:textColor="#808080" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/doispe"
        android:textStyle="bold"
        android:textColor="#808080"
/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的main.xml,我试图使按钮最透明,但我仍然希望看到它们,我不知道要添加什么以及添加位置,请更正我的xml,底部的低不透明度.有预谋的谢谢你:D

CSm*_*ith 15

检查如何在Android中为View设置不透明度(Alpha)

您可以设置对象背景的透明度,使用#XX808080,其中XX是alpha /透明度值.

android:background="#80FF0000"
Run Code Online (Sandbox Code Playgroud)

这将是一个半透明的红色背景.

您可以使用textColor属性以相同的方式设置按钮文本的透明度:

android:textColor="#80FF0000"
Run Code Online (Sandbox Code Playgroud)

您还可以通过动画中的代码实现

AlphaAnimation alphaAnim = new AlphaAnimation(1.0f, 0.5f);
alphaAnim.setDuration (400);
myButton.getBackground().startAnimation(alphaAnim);  // set alpha on background
Run Code Online (Sandbox Code Playgroud)

或直接:

myButton.getBackground().setAlpha(0.5f);   // added in API 11, sets alpha on background
Run Code Online (Sandbox Code Playgroud)

两种方法都将alpha设置为50%

最后,您可以尝试为您的XML添加android:alpha:

<Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/zece"
        android:textStyle="bold"
        android:textColor="#808080" 
android:alpha="0.5"
/>
Run Code Online (Sandbox Code Playgroud)