Activity透明/半透明效果的設(shè)置transparent(兩種實(shí)現(xiàn)方法)
更新時(shí)間:2013年02月27日 10:45:43 作者:
兩種方法實(shí)現(xiàn)Activity透明/半透明效果的設(shè)置,代碼思路很有調(diào)理,感興趣的朋友可以參考下,希望本文可以幫助到你
方法一:
res/values文件夾下建立styles.xml:
復(fù)制代碼 代碼如下:
<?xml version=“1.0″ encoding=“utf-8″?>
<style name="translucent">
<item name="android:windowBackground">@color/translucent_background</item>
<item name="android:windowIsTranslucent">true</item>
</style>
在該文件夾下在創(chuàng)建文件colors.xml
復(fù)制代碼 代碼如下:
<?xml version=“1.0″ encoding=“UTF-8″?>
<RESOURCES>
<color name="translucent_background">#60000000</color>
</RESOURCES>
有了這寫設(shè)置,就得告訴Activity用這寫設(shè)置.
AndroidManifest.xml中找到要彈出的activity,加入theme:
android:theme=”@style/translucent”
哎,不錯(cuò),確實(shí)透明了.但是問(wèn)題又來(lái)了,layout里的button不透明?。绻茏屗麄円餐该骰蛘甙胪该髂??那得設(shè)置窗口屬性.
復(fù)制代碼 代碼如下:
Window window=getWindow();
WindowManager.LayoutParams wl = window.getAttributes();
wl.flags=WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
wl.alpha=0.6f; 這句就是設(shè)置窗口里崆件的透明度的.0.0全透明.1.0不透明.
window.setAttributes(wl);
方法二:
今天試著做activity半透明的效果,做出來(lái)之后才發(fā)現(xiàn)想復(fù)雜了!很簡(jiǎn)單的幾句就可以實(shí)現(xiàn),不多說(shuō)了,貼代碼!
res/values/styles.xml
復(fù)制代碼 代碼如下:
<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>
res/values/color.xml
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_background">#50000000</color>
</resources>
注意:color.xml的#5000000前兩位是透明的效果參數(shù)從00--99(透明--不怎么透明),后6位是顏色的設(shè)置
manifest.xml
復(fù)制代碼 代碼如下:
<activity android:name=".TransparentActivity" android:theme="@style/Transparent">
</activity>
java代碼
復(fù)制代碼 代碼如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Transparent);
setContentView(R.layout.transparent);
}
您可能感興趣的文章:
- Android編程實(shí)現(xiàn)橫豎屏切換時(shí)不銷毀當(dāng)前activity和鎖定屏幕的方法
- Android App中實(shí)現(xiàn)向右滑動(dòng)銷毀功能的要點(diǎn)解析
- Android的Activity跳轉(zhuǎn)動(dòng)畫各種效果整理
- android的activity跳轉(zhuǎn)到另一個(gè)activity
- android PopupWindow 和 Activity彈出窗口實(shí)現(xiàn)方式
- Android基礎(chǔ)之Fragment與Activity交互詳解
- Android Activity之間傳遞圖片(Bitmap)的方法
- Android筆記之:App應(yīng)用之啟動(dòng)界面SplashActivity的使用
- android獲取當(dāng)前運(yùn)行Activity名字的方法
- Android Activity切換(跳轉(zhuǎn))時(shí)出現(xiàn)黑屏的解決方法 分享
- Android實(shí)現(xiàn)Activity界面切換添加動(dòng)畫特效的方法
- 詳解Android.activity銷毀流程的工作原理
相關(guān)文章
Android如何實(shí)現(xiàn)掃描和生成二維碼
這篇文章主要為大家詳細(xì)介紹了Android如何實(shí)現(xiàn)掃描和生成二維碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
Android開發(fā)實(shí)現(xiàn)從相冊(cè)中選擇照片功能詳解
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)從相冊(cè)中選擇照片功能,涉及Android權(quán)限控制、事件綁定、文件路徑與獲取等相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
Android編程實(shí)現(xiàn)在底端顯示選項(xiàng)卡的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)在底端顯示選項(xiàng)卡的方法,涉及Android界面線性布局、相對(duì)布局及選項(xiàng)卡設(shè)置相關(guān)操作技巧,需要的朋友可以參考下2017-02-02
Android?Flutter實(shí)現(xiàn)搜索的三種方式詳解
這篇文章主要為大家詳細(xì)介紹了Android?Flutter實(shí)現(xiàn)搜索的三種方式,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的可以了解一下2022-08-08
ActivityManagerService廣播并行發(fā)送與串行發(fā)送示例解析
這篇文章主要為大家介紹了ActivityManagerService廣播并行發(fā)送與串行發(fā)送示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Android自定義ViewGroup實(shí)現(xiàn)受邊界限制的滾動(dòng)操作(3)
這篇文章主要為大家詳細(xì)介紹了Android自定義ViewGroup實(shí)現(xiàn)受邊界限制的滾動(dòng)操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
Android自定義照相機(jī)Camera出現(xiàn)黑屏的解決方法
這篇文章主要介紹了Android自定義照相機(jī)Camera出現(xiàn)黑屏的解決方法,分析了黑屏出現(xiàn)的原因及參考解決方法,需要的朋友可以參考下2016-08-08
Android 帶進(jìn)度條的WebView 示例代碼
本文主要介紹Android WebView,這里提供實(shí)例代碼,和效果圖供大家參考,希望能幫助有需要的小伙伴2016-07-07

