主要.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>
这是我的 main.xml,我试图使按钮最透明,但我仍然想看到它们,但我不知道要添加什么以及在哪里添加,请使用按钮上的低不透明度纠正我的 xml。预谋的谢谢:D
check 如何在 Android 中设置视图的不透明度 (Alpha)
您可以设置对象背景的透明度,使用#XX808080,其中XX是alpha/透明度值。
android:background="#80FF0000"
这将是半透明的红色背景。
您可以以相同的方式使用 textColor 属性设置按钮文本的透明度:
android:textColor="#80FF0000"
也可以通过动画中的代码来实现
AlphaAnimation alphaAnim = new AlphaAnimation(1.0f, 0.5f);
alphaAnim.setDuration (400);
myButton.getBackground().startAnimation(alphaAnim); // set alpha on background
或直接:
myButton.getBackground().setAlpha(0.5f); // added in API 11, sets alpha on background
两种方法都将 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"
/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)