android 自定义对话框 背景透明

1、定义style:

<resources>

    <style
        name="dialog_fullscreen">
        <item
            name="android:windowFullscreen">true</item>
        <item
            name="android:windowNoTitle">true</item>
        <item
            name="android:windowBackground">@android:color/transparent</item>
    </style>
</resources>

2、定义layout文件:test_dialog.xml

<LinearLayout
    android:id="@+id/ll_dialog"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:background="#000000">

……

</LinearLayout>

3、代码中设置:

public class TestDialog extends Dialog

{

    public TestDialog(Context context)
    {
        super(context, R.style.dialog_fullscreen);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.test_dialog);

        // 设置背景透明度
        View ll = findViewById(R.id.ll_dialog);
        ll.getBackground().setAlpha(120);// 120为透明的比率
    }

}

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cruel/archive/2011/01/05/6118806.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
透明对话框 void TransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc, COLORREF colorTransparent, HPALETTE hPal ) { CDC dc, memDC, maskDC, tempDC; dc.Attach( hdcDest ); maskDC.CreateCompatibleDC(&dc); CBitmap maskBitmap; //add these to store return of SelectObject() calls CBitmap* pOldMemBmp = NULL; CBitmap* pOldMaskBmp = NULL; HBITMAP hOldTempBmp = NULL; memDC.CreateCompatibleDC(&dc); tempDC.CreateCompatibleDC(&dc); CBitmap bmpImage; bmpImage.CreateCompatibleBitmap( &dc, nWidth, nHeight ); pOldMemBmp = memDC.SelectObject( &bmpImage ); // Select and realize the palette if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && hPal ) { ::SelectPalette( dc, hPal, FALSE ); dc.RealizePalette(); ::SelectPalette( memDC, hPal, FALSE ); } hOldTempBmp = (HBITMAP) ::SelectObject( tempDC.m_hDC, hBitmap ); memDC.BitBlt( 0,0,nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY ); // Create monochrome bitmap for the mask maskBitmap.CreateBitmap( nWidth, nHeight, 1, 1, NULL ); pOldMaskBmp = maskDC.SelectObject( &maskBitmap ); memDC.SetBkColor( colorTransparent ); // Create the mask from the memory DC maskDC.BitBlt( 0, 0, nWidth, nHeight, &memDC, 0, 0, SRCCOPY ); // Set the background in memDC to black. Using SRCPAINT with black // and any other color results in the other color, thus making // black the transparent color memDC.SetBkColor(RGB(0,0,0)); memDC.SetTextColor(RGB(255,255,255)); memDC.BitBlt(0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND); // Set the foreground to black. See comment above. dc.SetBkColor(RGB(255,255,255)); dc.SetTextColor(RGB(0,0,0)); dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND); // Combine the foreground with the background dc.BitBlt(nXDest, nYDest, nWidth, nHeight, &memDC, 0, 0, SRCPAINT); if (hOldTempBmp) ::SelectObject( tempDC.m_hDC, hOldTempBmp); if (pOldMaskBmp) maskDC.SelectObject( pOldMaskBmp ); if (pOldMemBmp) memDC.SelectObject( pOldMemBmp ); dc.Detach(); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值