主.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
最佳答案
检查 How to Set Opacity (Alpha) for View in Android
您可以设置对象背景的透明度,使用#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"
/>
关于android - 按钮不透明度/透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20643999/