2013-07-24 65 views
3

我掙扎着一個小問題,我的問題是我在設計部分使用透明的編輯文本視圖,在4.2版本Android設備看起來不錯,很好,如果我檢查2.3版本及以下版本中顯示黑色編輯文本的相同編輯文本。這是我的編輯文本代碼。透明編輯文本視圖是不同的2.3版本和4.2版本

<EditText android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dip" 
      android:layout_weight="1" 
      android:alpha="0.3" 
      android:background="@drawable/reg_edittext" 
      android:ellipsize="end" 
      android:ems="10" 
      android:lines="1" 
      android:scrollHorizontally="true" 
      android:singleLine="true" 
      android:textColor="#ffffff" /> 

這裏是我的reg_edittext

<?xml version="1.0" encoding="utf-8"?> 
<!-- res/drawable/rounded_edittext.xml --> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp" > 
<solid android:color="#000000" /> 
    <corners android:bottomRightRadius="5dp" 
      android:bottomLeftRadius="5dp" 
      android:topLeftRadius="5dp" 
      android:topRightRadius="5dp"/> 
</shape> 

顯示在2.3版中的黑色編輯文本,在4.2呈現透明。回答我,我想查看相同的透明的2.3版本

回答

2

please check the link

android:alpha="0.3" this alpha property is added in API level 14. So in the previous version it map looks different depends on devices. 

嘗試改變化背景純色透明的,它可以幫助你。

android:color="#000000" to transparent color range- #FF000000 to #00000000 
3

儘管@ Sri的答案大部分是正確的,但並不完整。你看到不透明的黑色背景,因爲沒有添加下面的屬性,直到API級別(Android 3.0的):

幸運的是,你可以添加透明的顏色。爲了使背景色半透明,具有相同的0.3/30%的α值,改變solid聲明:

<solid android:color="#4C000000" /> 
0

您還必須指定字母,而指定的顏色,如果你想給的任何相同的透明度。因此,總顏色值應採用格式#AARRGGBB,其中AA - 是alpha顏色值(00 - transperant,FF-不透明),RR - 紅色,GG - 綠色,BB - 藍色。在你的情況下獲得完整的transperant背景,你必須指定像這樣:

android:textColor="#00000000" 
相關問題