当前位置: 代码迷 >> Android >> 怎么设置背景透明
  详细解决方案

怎么设置背景透明

热度:45   发布时间:2016-04-28 04:30:10.0
如何设置背景透明
我有一个xml文件布局,在service里面通过  
                mView = View.inflate( this, R.layout.match, null );
                                mWindowManager = ( WindowManager ) getSystemService( "window" );
  获得view,然后用
    mWindowManager.addView( mView, p );添加view,可是为什么add显示出来的背景不能为透明的呢?
ps:设置过#00000000无效。
无奈求助。。。。
其中p设置如下:
LayoutParams p = new LayoutParams( LayoutParams.TYPE_APPLICATION_PANEL );
p.flags = LayoutParams.FLAG_HARDWARE_ACCELERATED | LayoutParams.FLAG_NOT_FOCUSABLE;
p.token = windowToken;
p.x = x;
p.y = y;
p.width = w;
p.height = h;
p.gravity = 8388659;
布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/intro_bg"
    >

  <ImageView
      android:layout_marginTop="10dp" 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:scaleType="center"
      android:src="@drawable/unlock_tips" />
  
  <TextView 
      android:id="@+id/unlock_tv"
      android:layout_width="fill_parent"
      android:layout_height="25dp"
      android:layout_marginBottom="10dp"
      android:textSize="17dp"
      android:text=""
      android:gravity="center"
      android:textColor="#ffffff"
      android:layout_alignParentBottom="true"/>

</RelativeLayout>

------解决方案--------------------
LZ你是想打开一个不会覆盖当前窗口的弹出框样式的东东?
------解决方案--------------------
你设置下p.alpha的值试试,比如p.alpha = 0.5f。
------解决方案--------------------
你的xml:android:background="@drawable/intro_bg"   不是已经设置背景图片了吗
------解决方案--------------------
引用:
Quote: 引用:

你设置下p.alpha的值试试,比如p.alpha = 0.5f。

试了这个不行,因为这样会把imageview里的图片也变透明了,我只是想改变背景透明,不够还是谢谢你
2楼层主说的应该没问题的。。楼主你试试imageview弄到mainactivity.java再创建,不要在布局文件里边创建
------解决方案--------------------
引用:
Quote: 引用:

你的xml:android:background="@drawable/intro_bg"   不是已经设置背景图片了吗

这个是为了盖住黑色背景暂时放上去的

这就是你了,你设置了背景图片,在下面加入一条android:background="#00000000";试试
------解决方案--------------------
自定义style试试
------解决方案--------------------
这个应该是WindowManager 这个背景不是透明的吧。
我记的POpWindow中加布局文件的背景也不是透明的。好像得设置POpWindow本身的背景为透明才可以。WindowManager 应该也是和POpWindow类似自己默认有背景色

  相关解决方案