按钮不透明/透明度 [英] Button opacity/transparency

查看:208
本文介绍了按钮不透明/透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

main.xml中:

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>

这是我的main.xml中,我试图使按钮最透明的,但我想还是看到他们,我不知道该怎么添加和在哪里添加,请纠正我的XML与低透明度在bottons。 pmeditated $ P $谢谢:D

This is my main.xml, I am trying to make the buttons the most transparent, but I want still to see them and I don't know what to add and where to add, please correct my xml with the low opacity on bottons. Premeditated thank you:D

推荐答案

支票的如何设置不透明度(alpha)的视图中的Andr​​oid

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

You can set transparency on background of objects, use #XX808080, where XX is the alpha/transparency value.

android:background="#80FF0000"

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

this will be a half-transparent red background.

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

You can set transparency on the button text using the textColor property in the same manner:

android:textColor="#80FF0000"

您还可以通过code实现的动画

You can also achieve through code in an animation

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%

both methods set the alpha to 50%

最后,您可以尝试添加机器人:阿尔法为XML:

Lastly, you can try adding android:alpha for your XML:

<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"
/>

这篇关于按钮不透明/透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆