1. 程式人生 > >android對話方塊程式碼中設定背景為透明

android對話方塊程式碼中設定背景為透明

<span style="font-size:18px;">//建立背景透明的對話方塊 AlertDialog.THEME_HOLO_LIGHT
		AlertDialog.Builder b = new AlertDialog.Builder(myContext.getApplicationContext(), AlertDialog.THEME_HOLO_LIGHT);
		dialog = b.create();  </span>

網上還有一種,但是在android5.0以上,就不能讓背景透明瞭,實際上他們只是讓對話方塊的內容透明

<pre name="code" class="java"><span style="white-space:pre">		</span>//獲取dialog的佈局屬性
		WindowManager.LayoutParams wmParams = dialog.getWindow().getAttributes();
		//wmParams.format = PixelFormat.TRANSPARENT;  內容全透明
		wmParams.format = PixelFormat.TRANSLUCENT;  內容半透明
		wmParams.alpha=0.1f;    調節透明度,1.0最大 
//dialog設定各種屬性
dialog.getWindow().setAttributes(wmParams);

經實踐檢測,即使是new AlertDialog.Builder(myContext.getApplicationContext(), AlertDialog.THEME_HOLO_LIGHT);也不能使所有android裝置透明,有些android盒子,就還是留有白色背景,解決方法

AlertDialog.Builder b = new AlertDialog.Builder(myContext.getApplicationContext(), R.style.NoBackGroundDialog);
dialog = b.create();		
styles.xml:
<style name="NoBackGroundDialog" parent="@android:style/Theme.Holo.Light.Dialog">
	  	<item name="android:windowBackground">@android:color/transparent</item>		
	</style>

這裡不管是Theme.Holo.Light.Dialog,還是繼承其他parent,例如Theme.DeviceDefault.Dialog,都可以透明!!!

相關推薦

android對話方塊程式碼設定背景透明

<span style="font-size:18px;">//建立背景透明的對話方塊 AlertDialog.THEME_HOLO_LIGHT AlertDialog.Builder b = new AlertDialog.Builder(myContex

Android 在java程式碼設定EditText只接受數字輸入

在XML中的我就不多說了,不知道的童鞋可以去查EditText的XML屬性。 做到的專案需要動態生成EditText所以就只能在java程式碼中控制,EditText的屬性。 上程式碼: EditText et; et = (EditText) findViewById(R.id.et); // 方法1

Android在java程式碼設定margin

然則有些景象下,須要在java程式碼裡來寫,可是View本身沒有setMargin辦法,怎麼辦呢? 經由過程查閱android api,我們發明android.view.ViewGroup.MarginLayoutParams有個辦法setMargins(left, top, right, botto

VC對話方塊如何新增WM_ERASEBKGND訊息(OnEraseBkgnd函式)及對話方塊使用點陣圖背景透明

1、使用OnEraseBkgnd函式實現對話方塊點陣圖背景 BOOL CDisplayBmpBackGroundDlg::OnEraseBkgnd(CDC   *pDC)   //老婆:增加擦出背景函式{ CRect rect; GetClientRect(&rect);  CBitmap m_p

Android程式碼設定圖片,文字自定義顏色,Linearlayout等控制元件設定背景

平時專案中遇到的問題,在此記錄警示自己,也可使別人少走彎路。 ————–> 1. 程式碼中設定圖片,使用iv.setImageResource(R.mipmap.yishenghuo2);

android 適配dpi框架在程式碼設定TextView setTextSize時的使用

我這裡用的是阿杜的dpi適配框架,DisplayUtil是常見的單位轉換工具類,可自行搜尋 TextView .setTextSize()方法傳入的是sp值 檢視原始碼  /**      * S

android 在java程式碼動態設定控制元件的位置和設定片大小

需要動態改變佈局裡面控制元件的相對位置 如: 1.改變RelativeLayout佈局裡面某個控制元件的layout_toLeftOf 的屬性 RelativeLayout.Layoutparams params = (RelativeLayout.LayoutParams)view

Android程式碼設定控制元件的寬和高

//在程式碼中設定控制元件大小的方法 private Button mbtn; mbtn = (Button) findViewById(R.id.btn_test); LayoutParams lp; lp=mbtn.getLayoutParams

android程式碼設定控制元件的長和高

這裡介紹LinearLayout和RelativeLayout兩種佈局下的控制元件 LinearLayout.LayoutParams paramss = (LinearLayout.LayoutParams) imageview.getLayoutPar

Android studio2.0在app設定背景圖片及新增圖片資源

我還處於摸索階段,也是在慢慢倒騰,持續更新,希望能幫助到有需要的人 首先將需要的圖片轉成png格式(png格式的圖片顏色過渡平滑且支援透明度),牆紙或啟動畫面的圖片資源儲存為jpg格式。 將圖片儲存到相應的工程之下,不要放錯了。 某工程/app/src/m

Android TextView 程式碼設定 drawableLeft

1.在Android中的xml檔案中我們可以輕易的為TextView設定圖片,居左,或者居右。 <TextView android:id="@+id/tv_more" android:layout_width="

WPF設定PasswordBox空,背景文字提示

    繼上篇部落格textbox為空時,背景為文字提示,關於密碼框水印就不同於文字框了,可以寫個Brush就搞定,因為密碼框是沒有可以用於判斷輸入非空的依賴屬性的, 下面就說一下實現過程 1、新建一個類:PasswordBoxHelper.cs <span sty

Android程式碼設定字型大小

在xml檔案中字型大小用的畫素px android:textSize="@dimen/x40"<dimen name="x40">26.66px</dimen>然後在程式碼中

Android程式碼設定imageview的大小和位置(滿足單方向的放大縮小和任意位置的移動)

       許久以前,在我還是初中的時候,有過一個當網路小說家的夢想,誰知到如今,卻成一個程式設計師。享受生活,享受現在,做一個寫部落格的程式設計師,也算是了卻當初的半個夢想。                                                

UIKit和Cocos2d-x的整合使用;設定CCEAGLView背景透明,來顯示背後的UIView; 以及整合遇到的問題的解決方案

UIKit和Cocos2d-x的整合使用 原來我們的專案通過原始的UIKit來實現應用開發,但是現在需要往應用中增加禮物特效動畫,而禮物特效需要通過cocos2d-x來實現。晚上的方法大多都是通過建立初始的cocos2d工程,再在工程中增加UIKit的實現。最著名的介紹這個

Android設定Activity背景透明style

方法一: 通過Theme.Translucent @android:style/Theme.Translucent @android:style/Theme.Translucent.NoTitleBar

Android 使用MarginLayoutParams在Java程式碼設定View的margin屬性

1.簡介在View的設定中,我們很常會用到View的邊距設定.在XML中這個通過layout_margin屬性進行設定是很容易做到的。但是某些情況下我們需要設定layout_margin但卻不是在XML

Android TextView 程式碼設定DrawableLeft 圖片

xml中的textView的drawableLeft是這樣設定的 <TextView android:id="@ id/demoTextView" android:layout_width="wrap_content" android:layout_

android 程式碼設定dp單位的元件高度

原文地址:http://write.blog.csdn.net/postedit DisplayMetrics metrics = new DisplayMetrics() getWindowManager().getDefaultDisplay().getMetr

Android 程式碼設定Color引數

2014-09-25補充: Color.argb(16, 210, 35, 210) 原來Color類就可以實現,Paint的方案有些複雜了。 </pre><p></p><p></p><p>今天想繪製一