国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Activity透明/半透明效果的設(shè)置transparent(兩種實(shí)現(xiàn)方法)

2020-04-11 12:31:03
字體:
供稿:網(wǎng)友

方法一
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í)透明了.但是問題又來了,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半透明的效果,做出來之后才發(fā)現(xiàn)想復(fù)雜了!很簡單的幾句就可以實(shí)現(xiàn),不多說了,貼代碼!
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);  

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大安市| 龙胜| 滕州市| 拉孜县| 文昌市| 禹城市| 阿瓦提县| 横山县| 保山市| 伊春市| 朝阳市| 韶山市| 中方县| 遂平县| 浦城县| 葫芦岛市| 兴化市| 桑日县| 蒙阴县| 竹山县| 南川市| 靖州| 德阳市| 白银市| 洪江市| 二连浩特市| 新巴尔虎右旗| 夏津县| 临澧县| 蕲春县| 阜南县| 黑山县| 铁岭市| 宁南县| 德保县| 宜良县| 汪清县| 潜山县| 铁力市| 家居| 庆城县|