// ==========文本框透明============================
做android页面如何把文本框背景做成透明的
还需要设置字体颜色,不然没有了背景,字体和窗体背景都是黑色的什么都看不到
<EditText android:text="EditText" android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" ></EditText>
// ==========文本框等背景半透明透明============================
1、java代碼實現:
View v = findViewById(R.id.content);//找到你要設透明背景的layout 的id v.getBackground().setAlpha(100);//0~255透明度值
---------------
int color = Color.argb(127, 255, 0, 255); // 半透明的紫色然後設置 setColor(color);
2.xml檔中實現:
<Button android:background="#e0000000" ... /> //半透明 <Button android:background="#00000000" ... /> //透明
說明:前兩個f是表示透明 度,從00到ff後面的就是RGB的值
// ==========Activity透明效果=============
AndroidManifest.xml
<activity android:name="org.ourunix.android.FreneticActivity" android:icon="@drawable/small_pic.png" android:label="@string/freneticLabel" android:style="@android:style/Theme.Translucent"> </activity>
// ==========Activity半透明效果=============
values/styles.xml
<resources> <style name="Transparent"> <item name="android:windowBackground">@color/transparent_background</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item> </style> </resources>
values/color.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="transparent_background">#50000000</color> </resources>
注意:color.xml的#5000000前两位是透明的效果参数从00--99(透明--不怎么透明),后6位是颜色的设置
manifest.xml
<activity android:name=".TransparentActivity" android:theme="@style/Transparent"> </activity>
java代码
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(R.style.Transparent); setContentView(R.layout.transparent); }
// ==========Activity半透明透明以及非全屏幕窗体效果=============
value/bg_style.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- 定义一个样式,继承android系统的对话框样式 android:style/Theme.Dialog--> <style name="Theme.SelectPhotosActivity" parent="android:style/Theme.Dialog"> <item name="android:windowBackground">@drawable/bg_select</item> </style> </resources>
drawable/bg_select.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#00000000" /> <stroke android:width="6dp" color="#ffff0000" /> <corners android:radius="3dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape>
AndroidManifest.xml
<activity android:name="com.xxx.image.SelectImagesActivity" android:theme="@style/Theme.SelectPhotosActivity"> </activity>