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

android透明色代碼

發布時間: 2022-06-23 19:13:27

⑴ 如何讓android 的activity變成完全透明的

  1. resources 添加一個style標簽 parent 繼承 android:Theme.Light.NoTitleBar

  2. item android:windowBackground 屬性可以設置一個透明顏色

  3. 然後在需要透明的Activity onCreate 中或者項目清單文件中設置這個自定義皮膚即可

示例代碼:

<stylename="customeTheme"parent="android:Theme.Light.NoTitleBar">
<!--設置window背景顏色或圖片也就是Activity的窗口背景-->
<itemname="android:windowBackground">@color/window_bg_color</item>
<!--狀態欄視圖背景透明4.4系統支持-->
<itemname="android:windowTranslucentStatus">true</item>
<!--屏幕下面的虛擬操作按鈕不透明-->
<itemname="android:windowTranslucentNavigation">false</item>
<!--軟鍵盤顯示時,視圖自動上移-->
<itemname="android:windowSoftInputMode">stateAlwaysHidden|adjustResize</item>
</style>

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

#88333333為顏色代碼,採用十六進制繪制:
其中#為固定的
88為透明度從00到99之間,由透明到完全不透明
333333為十六進制的顏色

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

以Android Studio為例,步驟如下:

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

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

設置Android中控制項的顏色透明度,可自由設置在layout里也可以在activity里
eclipse

1

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

⑸ 如何實現Android透明導航欄

實現功能

1.步驟:

1) 創建一個工程,主布局就先做一個ImageView,自己找個好看的圖片做src。
2) 在Activity重寫的onCreate方法中獲得窗口視圖對象(DecorView)
3) 設置DecorView的SystemUiVisibility
4) 設置導航條、狀態欄的顏色–>透明
5) 獲取當前Activity的ActionBar並隱藏

2.具體代碼和注釋:

獲取DecorView對象

java">@Override
protectedvoidonCreate(BundlesavedInstanceState){
...
ViewdecorView=getWindow().getDecorView();
...
}

設置SystemUiVisibility

intoption=View.SYSTEM_UI_FLAG_FULLSCREEN//全屏標記
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN//布局全屏標記,避免退出全屏模式時內容被覆蓋
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隱藏導航欄標記
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION//布局隱藏導航欄標記,同理
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY//粘性沉浸體驗
|View.SYSTEM_UI_FLAG_LAYOUT_STABLE;//確保上述標記穩定//此方法用來設置系統UI的可見性,系統UI包括狀態欄、ActionBar、導航欄devorView.setSystemUiVisibility(option);

設置狀態欄、導航欄的顏色:

getWindow().setStatusBarColor(Color.TRANSPARENT);//Color.TRANSPARENT=0表示#00000000即透明顏色
getWindow().setNavigationBarColor(Color.TRANSPARENT);

獲取本頁面的ActionBar並隱藏起來

ActionBaractionBar=getSupportActionBar();//注意:此處用的Activity繼承的是
AppCompatActivity(它繼承的是FragmentActivity)
//所以調用的是getSupport...方法,如果繼承Activity則直接調用get...方法
assertactionBar!=null;//這一句可以不理會,反正我是Ctrl+F1提示出來的,意思其實是判斷如果actionBar不為空則向下執行。
actionBar.hide();

注意:最後一點注意事項是:只支持Android API 21以上的手機

⑹ 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代碼的形式讓button變成圓角 透明,如圖

步驟如下:
------------------------------------------------------------------------
1. 先在res/drawable中定義一個shape.xml文件,具體的顏色你可以自己調
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<!-- 填充的顏色:這里設置背景透明 -->
<solid android:color="@android:color/transparent" />
<!-- 邊框的顏色 :不能和窗口背景色一樣-->
<stroke
android:width="3dp"
android:color="#ffffff" />
<!-- 設置按鈕的四個角為弧形 -->
<!-- android:radius 弧形的半徑 -->
<corners android:radius="5dip" />

<!-- padding:Button裡面的文字與Button邊界的間隔 -->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
------------------------------------------------------------------------
2. 在你的Activity的xml(比如activity_main.xml)中定義按鈕
<Button
android:id="@+id/roundButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:text=" 圓角按鈕 " />

⑻ 如何讓android的actionbar浮動且透明

如上圖所示,谷歌地圖的actionbar是透明的,且浮動在整個布局之上,沒有佔用布局空間。其實要做到這樣的效果,我們首先想到的是兩個方面:
1.將讓actionbar浮動起來。
2.給actionbar一個背景,可以為顏色也可以為圖片。
下面我以背景色為顏色舉個例子。
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);ActionBar actionBar = getActionBar();actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));

google的actionbar是分為上下兩欄顯示的,上面的代碼只能設置頂部actionbar的背景色,為了讓下面的背景色一致,還需要添加一行代碼:
actionBar.setSplitBackgroundDrawable(newColorDrawable(Color.parseColor("#330000ff")));

如果我們不想在代碼中設置actionbar背景,而是在style中修改xml,可以自定義actionbar,然後設置下面三個屬性:
<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> <item name="android:background">@drawable/ab_stacked_solid_inverse_holo</item> <item name="android:backgroundStacked">#346c36</item> <item name="android:backgroundSplit">@drawable/ab_stacked_solid_inverse_holo</item> </style>

其中的background和setBackgroundDrawable對應,backgroundSplit和setSplitBackgroundDrawable對應,而backgroundStacked代表的是actionbar選項卡的背景色。
但是actionbar的背景如果設置為純色,或者為不透明的圖片,那麼上面的方法無法使actionbar達到透明的效果。注意上面的代碼中,我們的顏色值並不是純色的而是有一定的透明度。#330000ff的前兩位代表透明度。

⑼ 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>

⑽ 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>

熱點內容
雲伺服器選擇什麼系統 發布:2024-05-09 01:55:51 瀏覽:968
mel腳本編程全攻略 發布:2024-05-09 01:54:43 瀏覽:479
如何在機房安裝ntp伺服器 發布:2024-05-09 01:13:57 瀏覽:206
ideajavaidea 發布:2024-05-09 01:02:14 瀏覽:965
oas存儲 發布:2024-05-09 00:57:49 瀏覽:801
android點擊彈出菜單 發布:2024-05-09 00:56:52 瀏覽:99
大家對雲伺服器認知度 發布:2024-05-09 00:46:00 瀏覽:659
思科視頻會議如何配置 發布:2024-05-09 00:45:59 瀏覽:669
centos安裝ftp伺服器配置 發布:2024-05-09 00:45:06 瀏覽:81
幕布電腦版伺服器連接失敗怎麼整 發布:2024-05-09 00:38:21 瀏覽:723