国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 康定县| 曲水县| 保定市| 彰化县| 深州市| 日照市| 合川市| 长垣县| 西宁市| 沅陵县| 临夏市| 平山县| 手游| 武安市| 周宁县| 弋阳县| 亳州市| 新余市| 长岭县| 万州区| 郴州市| 永靖县| 锦州市| 锦屏县| 罗源县| 郯城县| 平潭县| 蕉岭县| 中方县| 城口县| 黄梅县| 都匀市| 淮阳县| 凤凰县| 本溪市| 广东省| 盐源县| 石城县| 安阳市| 屏山县| 宁城县|