如何使按钮,在我的应用程序透明可见尚 [英] How to make button transparent in my app yet visible

查看:101
本文介绍了如何使按钮,在我的应用程序透明可见尚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的按钮是透明的,因为我对活动作为背景的​​图片。
如果按钮不是透明的,这些按钮都覆盖了图像和图像背景好像没用。

如果我用的android:背景=@机器人:彩色/透明,它正在除了其上的文字我的按钮完全不可见。所以,我需要的按钮,是透明的,只要它应该是可见的,有一个按钮。 code段将AP preciated。

 <按钮
机器人:ID =@ + ID / new_button
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@机器人:彩色/透明//这一行使得按钮完全不可见。
机器人:文字=@字符串/标签/>


解决方案

如果你只是想白色边框,文本/图标的按钮,但按钮背景透明创建下面的绘制(我把它命名为button_border.xml)

 <?XML版本=1.0编码=UTF-8&GT?;<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目>
        <形状和GT;
            <中风
                机器人:颜色=@机器人:彩色/白
                机器人:宽=1DP/>
            [固体机器人:色=@机器人:彩色/透明/>
        < /形状>
    < /项目>
< /选择>

和使用它作为按钮的背景:

 <按钮
    。
    。
    。
    机器人:背景=@绘制/ button_border
    />

我猜还有一个更优雅的方式与主题做到这一点,但我不那么远呢。在button_border可绘制可以添加圆角和诸如此类的东西...

I want my buttons to be transparent as I have an image on the activity as a background. If the buttons are not transparent, those buttons are covering the image and image background seems useless.

If I use android:background="@android:color/transparent", it is making my button completely invisible except the text on it. So, I need the button to be transparent provided it should be visible that there is a button. Code snippet would be appreciated.

<Button
android:id="@+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"  //this line makes the button completely invisible.
android:text="@string/label" />

解决方案

If you just want white borders, and the text/icons in the button, but the button background transparent create the following drawable (I named it button_border.xml):

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <stroke
                android:color="@android:color/white"
                android:width="1dp" />
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
</selector>

And use it as a background for the button:

<Button
    .
    .
    .
    android:background="@drawable/button_border"
    />

I'd guess there is a more elegant way to do it with themes, but I'm not that far yet. In the button_border drawable you can add rounded corners and whatnot...

这篇关于如何使按钮,在我的应用程序透明可见尚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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