當前位置:首頁 » 安卓系統 » android布局透明度

android布局透明度

發布時間: 2023-02-23 08:25:23

A. 如何設置Android中控制項的顏色透明度

設置Android中控制項的顏色透明度需要設置設置控制項的background屬性設置方法如下。

1、使用Android studio創建一個Android 項目,如下圖:

B. 如何設置Android中控制項的顏色透明度

Android中設置ImageView控制項的圖片的透明度應該調用View的api,以下為示例:
1、用android系統的透明效果
Java代碼
android:background="@android:color/transparent"
例如
設置按鈕
Java代碼
<Button
android:background="@android:color/transparent"
android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>
2、用ARGB來控制
Java代碼
半透明<Button
android:background="#e0000000"
/>
透明<Button
android:background="#00000000"
/>
3、設置alpha
Java代碼
View
v
=
findViewById(R.id.content);
v.getBackground().setAlpha(100);
說明:
0~255透明度值,0表示完全不透明,255表示完全透明。

C. 怎樣將android控制項背景設置成透明

1、打開安卓的配置文件。

2、只需要在配置文件中把需要設置為透明的activity的樣式設置為android:theme="@android:style/Theme.Translucent"

3、這樣就可以把背景設置為透明。

D. android 怎麼設置線性布局 幀布局 全透明

Android設置線性布局 幀布局 全透明如下

1、LinearLayout(線性布局)
[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/mobile" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/mobile" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button"

android:id="@+id/button"/>

<CheckBox

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

</LinearLayout>

2、RelativeLayout(相對布局)

[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content">

<TextView

android:layout_width="100dp"

android:layout_height="wrap_content"

android:text="@string/number"

android:id="@+id/numberlabel" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:id="@+id/number"

android:layout_toRightOf="@id/numberlabel"

android:layout_alignTop="@id/numberlabel"

android:layout_marginLeft="5dp"/>

</RelativeLayout>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/content" />

<EditText

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:minLines="3"

android:maxLines="3"

android:id="@+id/content"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button"

android:id="@+id/button"/>

</LinearLayout>

3、TableLayout(表格布局 兩行兩列)
[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

Android:stretchColumns="1">

<TableRow>

<TextView

android:text="@string/table_lable1"
android:padding="3dip"/>

<TextView

android:text="@string/table_lable2"

android:gravity="right"

android:padding="3dip"/>

</TableRow>

<TableRow>

<TextView

android:text="@string/table_lable1"
android:padding="3dip"/>

<TextView

android:text="@string/table_lable2"

android:gravity="right"

android:padding="3dip"/>

</TableRow>

</TableLayout >

4、FrameLayout(幀布局)顯示控制項會進行疊加,後者會疊加在前者之上

[html] view plainprint?
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<ImageView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:src="@drawable/movie" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/play"

android:layout_gravity="center"/>

</FrameLayout>

E. Android 透明度設置詳解

格式:

android:background="#XXxxxxxx"(顏色可以寫在color中)

說明:半透明顏色值不同於平時使用的顏色,半透明顏色值共8位,前2位是透明度,後6位是顏色。也就是說透明度和顏色結合就可以寫出各種顏色的透明度。下面是透明度說明表,供大家參考。

部分透明度示例:

setAlpha()的括弧中可以填0–255之間的數字。數字越大,越不透明。

注意點:
在5.0以上系統時,有些機型會出現莫名其妙的顏色值不起作用,變成透明了,也就是用此方法會導致其他共用一個資源的布局(例如:@color/white)透明度也跟著改變。比如text用上述方法設置成透明後,項目中,其他用到text顏色值的控制項,都變成透明了。

原因:在布局中多個控制項同時使用一個資源的時候,這些控制項會共用一個狀態,例如ColorState,如果你改變了一個控制項的狀態,其他的控制項都會接收到相同的通知。這時我們可以使用mutate()方法使該控制項狀態不定,這樣不定狀態的控制項就不會共享自己的狀態了。

android:alpha的值為0~1之間的數。數字越大,越不透明。1表示完全不透明,0表示完全透明。

說道Activity透明,發現網上的基本上都已經過時,在有v7以上的控制項都無法實現,均會報錯

所以如若你的布局xml文件有 support-V7 上的控制項的話,<style name="translucent">里的name要前要添加 AppTheme,如:

F. 如何設置Android中控制項的顏色透明度

設置Android中控制項的顏色透明度,可自由設置在layout里也可以在activity里 #ff000000 此為16進制顏色代碼, 前2位ff為透明度,後6位為顏色值(000000為黑色,ffffff為白色,可以用ps等軟體獲取)。 透明度分為256階(0-255),計算機上用16進製表示為(00-ff)。透明就是0階,不透明就是255階,如果50%透明就是127階(256的一半當然是128,但因為是從0開始,所以實際上是127)。 0進制的255換算成16進制是ff,127換算成16進制是7f,#7f000000 代表50%透明度的黑色。 (寫成#50000000當然是不行的)進制轉換可使用win7自帶計算器(轉為科學型)。例:25%透明度的一種紅色「#3ff70000

G. 如何設置Android中控制項的顏色透明度

android:background="#a000"
這條屬性第一位表示設置透明度0-f 越大表示越不透明
後面位表示RGB顏色的值

H. android標題欄透明度漸變

<alpha>標簽為alpha透明度節點
android:fromAlpha="1.0" 設置動畫起始透明度為1.0 表示完全不透明
android:toAlpha="0.0"設置動畫結束透明度為0.0 表示完全透明
也就是說alpha的取值范圍為0.0 - 1.0 之間

這個動畫布局設置動畫從完全不透明漸變到完全透明。

view plain

<?xml
version="1.0"
encoding="utf-8"?>

<alpha
xmlns:android="http://schemas.android.com/apk/res/android"

android:fromAlpha="1.0"

android:toAlpha="0.0"

android:repeatCount="infinite"

android:ration="2000">

</alpha>

代碼實現

view plain

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public
class AlphaActivity extends Activity {
/**顯示動畫的ImageView**/

ImageView mImageView = null;

/**透明動畫**/

Animation mAnimation = null;
@Override

public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.translate);

/**拿到ImageView對象**/

mImageView = (ImageView)findViewById(R.id.imageView);

/**載入透明動畫**/

mAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha);

/**播放透明動畫**/

mImageView.startAnimation(mAnimation);
}
}

I. android導航欄與狀態欄顏色及透明度

首先創建一個空項目,如下圖

可以看到狀態欄是白字黑背景, 導航欄也是白圖標黑背景
嘿嘿, 我們先把狀態欄隱藏掉,在添加一個ImageView, 讓ImageView做背景(方便查看)

樣子如下:

將狀態欄和導航欄設置透明, 找到 Manifest.xml 文件, 在主題樣式中修改

android:statusBarColor 設置狀態欄背景色
android:navigationBarColor 同上
android:windowLightStatusBar 設置狀態欄文字色, true為深色, false為白色
android:windowLightNavigationBar 同上
android:windowTranslucentStatus 設置狀態欄半透明狀態, true為半透明, false為不透明
android:windowTranslucentNavigation 同上

最後兩個半透明狀態下面沒用, 可自己嘗試看效果

效果圖如下:

可以看到導航欄與狀態欄並沒有透明,原因是默認不能佔用狀態欄空間與導航欄空間,根布局背景為白色,所有這里顯示白色
可以通過設置 getWindow().getDecorView().setSystemUiVisibility() 來適配

View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 適配狀態欄空間
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 適配導航欄空間
效果如下:

J. Android 背景透明度設置總結

在需求上遇到背景設置透明度還是比較常見的,設置透明度有幾種方式,但是不同的場景應用下,不同的方式可能會出現一些問題。針對開發過程中的需求做以下總結。

按鈕點擊

布局

輸入框背景 search_title_bg

背景透明度設置比較常見,mutate()方法,可以解決背景透明狀態設置異常的現象。這里只記載需求開發中遇到的問題,可能還有其他方式,歡迎分享!!

熱點內容
安卓微信淺色模式怎麼恢復 發布:2025-05-16 06:27:53 瀏覽:238
美嘉演算法口訣 發布:2025-05-16 06:03:15 瀏覽:952
c程序編譯連接 發布:2025-05-16 06:02:36 瀏覽:964
腳本魔獸 發布:2025-05-16 06:01:52 瀏覽:330
文件夾python 發布:2025-05-16 06:01:43 瀏覽:627
電腦我的世界伺服器游戲幣 發布:2025-05-16 05:27:25 瀏覽:488
索尼手機為什麼不能用安卓10 發布:2025-05-16 05:18:46 瀏覽:784
蔚來es6選擇哪些配置實用 發布:2025-05-16 05:18:05 瀏覽:130
小米如何掃碼wifi密碼 發布:2025-05-16 05:13:38 瀏覽:807
樓層密碼是什麼意思 發布:2025-05-16 05:13:37 瀏覽:13