當前位置:首頁 » 安卓系統 » android設置顏色透明

android設置顏色透明

發布時間: 2022-06-13 03:02:32

❶ android中怎樣把背景透明

實現方式一(使用系統透明樣式)
通過配置 Activity 的樣式來實現,在 AndroidManifest.xml 找到要實現透明效果的 Activity,在 Activity 的配置中添加如下的代碼設置該 Activity 為透明樣式,但這種實現方式只能實現純透明的樣式,無法調整透明度,所以這種實現方式有一定的局限性,但這種方式實現簡單。
android:theme="@android:style/Theme.Translucent"

<activity
android:name="cn.sunzn.transact.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

實現方式二(使用自定義透明樣式)
這種方式的實現同樣要配置 Activity 的樣式,只不過這里的樣式是我們自定義的。具體實現過程如下:
1 在 res/values/color.xml 文件下加入一個透明顏色值,這里的 color 參數,是兩位數一個單位,前兩位數是透明度,後面每兩位一對是16進制顏色數字,示例中為白色。
<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="translucent_background">#80000000</color>

</resources>

2 在 res/values/styles.xml 文件中加入一個自定義樣式,代碼如下。

<!-- item name="android:windowBackground" 設置背景透明度及其顏色值 -->
<!-- item name="android:windowIsTranslucent" 設置當前Activity是否透明-->
<!-- item name="android:windowAnimationStyle" 設置當前Activity進出方式-->
<style name="translucent">
<item name="android:windowBackground">@color/translucent_background</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
</style>

3 在 AndroidManifest.xml 找到要實現透明的 Activity,在想要實現透明的 Activity 中配置其屬性,代碼如下;也可在該 Activity 的 onCreat() 方法中調用 setTheme(R.style.translucent) 來實現。

<activity
android:name="cn.sunzn.transact.MainActivity"
android:label="@string/app_name"
android:theme="@style/translucent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

❷ android Button 怎麼把背景設置透明

Android控制項設置邊框,或者背景可以使用XML來配置,背景透明只需要設置solid 的值為 #00000000即可,前面兩位是透明度,後面6位是RGB顏色值,具體示例代碼如下:
1.在drawable新建一個 buttonstyle.xml的文件,內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 連框顏色值 --><item>
<shape>
<solid android:color="#ff0000" />
</shape>
</item>
<!-- 主體背景顏色值 -->
<item android:bottom="3dp" android:right="3dp">
<shape>
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
</layer-list>

2.然後在布局文件裡面引入這個xml,示例代碼如下:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:background="@drawable/buttonstyle" />

❸ 請教android怎麼讓控制項背景透明

以Android Studio為例,步驟如下:

1、直接打開相關窗口,在Android-app-res-layout的空白處點擊滑鼠右鍵並選擇New-Layoutresource file。

❹ android 如何把一個 RelativeLayout或ImageView背景設為透明

設置背景為透明
1、設置背景為透明
<ImageView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:background="@android:color/transparent"/><!--#00000000-->也可以設置顏色值,前兩位為透明度
2、設置背景透明度
<ImageView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"/>
相應的也可以在java代碼中設置透明

❺ android 為什麼背景設置為透明

方法一: 只要在配置文件內activity屬性配置內加上 android:theme="@android:style/Theme.Translucent" 就好了。 這樣就調用了android的透明樣式! 方法二: 先在res/values下建colors.xml文件,寫入: <?xmlversionxmlversion="1.0"encoding="UTF-8"?> <resources> <colornamecolorname="transparent">#9000</color> </resources> 這個值設定了整個界面的透明度,為了看得見效果,現在設為透明度為56%(9/16)左右。

❻ android編程如何把現有的背景圖片設置成透明的

方法一:
只要在配置文件內activity屬性配置內加上

android:theme="@android:style/Theme.Translucent"

就好了。

這樣就調用了android的透明樣式!
方法二:
先在res/values下建colors.xml文件,寫入:
<?xmlversionxmlversion="1.0"encoding="UTF-8"?>

<resources>

<colornamecolorname="transparent">#9000</color>

</resources>
這個值設定了整個界面的透明度,為了看得見效果,現在設為透明度為56%(9/16)左右。

❼ android中怎麼設置color為透明顏色或者半透明顏色

正常設置顏色是「#」後面加6位16進制數字,在這6位前面再加兩位就是用來設置透明度的。

❽ android studio activity怎麼設置透明背景

Android studio在Manifest.xml中找到對應的activity在裡面加上android:theme="@android:style/Theme.Translucent"即可背景透明,如果還想取消標題欄和全屏的畫可以將style/改為Theme.Translucent.NoTitleBar.Fullscreen

❾ android怎麼動態設置透明度

工具

eclipse

方法

  1. #ff000000 此為16進制顏色代碼,前2位ff為透明度,後6位為顏色值

  2. 透明度分為256階(0-255),計算機上用16進製表示為(00-ff)

  3. 10進制的255換算成16進制是ff,127換算成16進制是7f

  4. 適用腳本

熱點內容
內置存儲卡可以拆嗎 發布:2025-05-18 04:16:35 瀏覽:330
編譯原理課時設置 發布:2025-05-18 04:13:28 瀏覽:371
linux中進入ip地址伺服器 發布:2025-05-18 04:11:21 瀏覽:606
java用什麼軟體寫 發布:2025-05-18 03:56:19 瀏覽:27
linux配置vim編譯c 發布:2025-05-18 03:55:07 瀏覽:100
砸百鬼腳本 發布:2025-05-18 03:53:34 瀏覽:935
安卓手機如何拍視頻和蘋果一樣 發布:2025-05-18 03:40:47 瀏覽:729
為什麼安卓手機連不上蘋果7熱點 發布:2025-05-18 03:40:13 瀏覽:798
網卡訪問 發布:2025-05-18 03:35:04 瀏覽:505
接收和發送伺服器地址 發布:2025-05-18 03:33:48 瀏覽:367