2015-11-13 154 views
0
AndroidStudio 1.5 

你好,创建一个透明背景,但保留文本和图标不透明

我想创建一个透明背景的图标和文字上。但我不想让图标或文字透明。在dialer_pad.xml我试图设置阿尔法,但每次我这样做的图标和文字也将变得透明。

正如你所看到的图标和文字是透明的。我只是想让背景透明。

enter image description here

我已经尝试了很多事情来设置阿尔法只得到周围的背景是透明的,而留下的文字和图标独。我认为制作一个图层列表可能会起作用。

这可能吗?

任何建议非常感谢,

contacts.xml

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingBottom="8dp" 
    android:background="@drawable/inner_border"> 

    <ImageView 
     android:id="@+id/ivContacts" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:padding="16dp" 
     android:src="@drawable/ic_people_white_48dp" 
     android:layout_gravity="center"/> 

    <TextView 
     android:id="@+id/tvHold" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Contacts" 
     android:textSize="12sp" 
     android:textColor="@android:color/white" 
     android:fontFamily="sans-serif-condensed" 
     android:layout_gravity="bottom|center"/> 
</FrameLayout> 

call.xml

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingBottom="8dp" 
    android:background="@drawable/right_border"> 

    <ImageView 
     android:id="@+id/ivSwitch" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_gravity="center" 
     android:padding="16dp" 
     android:src="@drawable/ic_phone_white_48dp" /> 

    <TextView 
     android:id="@+id/tvHold" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Make Call" 
     android:textSize="12sp" 
     android:fontFamily="sans-serif-condensed" 
     android:textColor="@android:color/white" 
     android:layout_gravity="bottom|center"/> 
</FrameLayout> 

dialer_pad.xml

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/outer_border" 
    android:alpha="0.5"> 

    <TableRow> 
     <include 
      layout="@layout/call" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

     <include 
      layout="@layout/contacts" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 
    </TableRow> 
</TableLayout> 

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.ssd.MainActivity" 
    android:gravity="center_vertical|center_horizontal" 
    android:background="@drawable/background"> 

    <include layout="@layout/dialer_pad"/> 
</RelativeLayout> 
+0

的getBackground()。setAlpha()犯规帮助你吗? – Nanoc

+0

带有alpha的FrameLayout容器0-1 里面的文字,图标 – pvllnspk

+0

@pvllnspk在FrameLayout上设置alpha值将为孩子添加透明度,以便图片和文字透明。我只想要文字和图标所在的背景是透明的。不加任何透明地留下图标和文字。 – ant2009

回答

1

你可以在你的outer_border.xml一个colortransparency代替:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/outer_border" > 

... 
</TableLayout> 

如果你想transparent blue你可以有它这样的:在 “dialer_pad.xml” #550000FF

+0

@Iuiscosta,实际上工作得很好。这是迄今为止最好的答案。 – ant2009

0

与方式,阿尔法与他们所有的孩子,包括有效。 因此,您需要删除dialer_pad.xml的TableLayout中的alpha。

并编辑你的孩子的布局。

contacts.xml

<FrameLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingBottom="8dp" 
     > 
     <ImageView 
      android:id="@+id/ivContacts" 
      android:layout_height="match_parrent" 
      android:layout_width="match_parrent" 
      android:alpha="0.5" 
      android:background="@drawable/inner_border"/> 

     <ImageView 
      android:id="@+id/ivContacts" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:padding="16dp" 
      android:src="@drawable/ic_people_white_48dp" 
      android:layout_gravity="center"/> 

     <TextView 
      android:id="@+id/tvHold" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Contacts" 
      android:textSize="12sp" 
      android:textColor="@android:color/white" 
      android:fontFamily="sans-serif-condensed" 
      android:layout_gravity="bottom|center"/> 
    </FrameLayout> 

同样与call.xml

+0

@ZaiNguyen,我试过你的建议,但除非我有什么不对。任何事情都没有透明度。我只想要文字和图标所在的背景是透明的。图标或文字没有透明度。希望我清楚。谢谢。 – ant2009