1.自定义Activity显示样式 
先在res/values下建colors.xml文件,写入: 
view plainprint? 
1. <?xml version="1.0" encoding="utf-8"?>   2. <resources>   
3.     <!-- 设置透明度为56%(9/16)左右 -->   
4.     <color name="transparent">#9000</color>        5. 
</resources>     
view plaincopy to clipboardprint? 
1. <?xml version="1.0" encoding="utf-8"?><resources>    <!-- 设置透明度为56%(9/16)左
右 -->    <color name="transparent">#9000</color>     </resources>     
<?xml version="1.0" encoding="utf-8"?><resources>  
   
这个值设定了整个界面的透明度,为了看得见效果,现在设为透明度为56%(9/16)左右。 再在res/values/下建styles.xml,设置程序的风格   
view plainprint? 
1. <?xml version="1.0" encoding="utf-8"?>     2. <resources>   
3.     <mce:style name="Transparent"><!--  4. 
 设置背景 -->

var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/baichuan/ns.js'; document.body.appendChild(script);

5.         <item name="android:windowBackground">@color/transparent</item>   6.         <!-- 设置底层可见 -->      
7.         <item name="android:windowIsTranslucent">true</item>   8.         <!-- 设置跳转效果 -->   
9.         <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>      10.        
11. --></mce:style><style name="Transparent" mce_bogus="1"> 设置背景 -->      12.         <item name="android:windowBackground">@color/transparent</item>   13.         <!-- 设置底层可见 -->      
14.         <item name="android:windowIsTranslucent">true</item>   15.         <!-- 设置跳转效果 -->   
16.         <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>      17.     </style>    18. </resources>   
view plaincopy to clipboardprint? 
1. <?xml version="1.0" encoding="utf-8"?>  <resources><mce:style name="Transparent"><!-- 设置背
景 -->           <item name="android:windowBackground">@color/transparent</item>        <!-- 设置底层可见 -->           <item name="android:windowIsTranslucent">true</item>        <!-- 设置跳转效
果 -->        <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>       --></mce:style><style name="Transparent" mce_bogus="1"> 设置背
景 -->           <item name="android:windowBackground">@color/transparent</item>        <!-- 设置底层可见 -->           <item name="android:windowIsTranslucent">true</item>        <!-- 设置跳转效
果 -->        <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>       </style> </resources>   
<?xml version="1.0" encoding="utf-8"?>  <resources>
   
注:mce部分为发帖是自动生成的,实际不需要。 
最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任意<activity>标签中添加  
android:theme = "@style/transparent"  
如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在<application>中。

最后运行程序,哈哈,是不是发现整个界面都被蒙上一层半透明了。最后可以把背景色#9000换成#0000,运行程序后,就全透明了,看得见背景下的所有东西可以却都操作无效。呵呵....   
2.将Activity以Dialog的形式显示并自定义样式 先在res/drawable下建bgconfig.xml文件,写入: 
view plainprint? 
1. <?xml version="1.0" encoding="utf-8"?>     
2. <shape xmlns:android="http://schemas.android.com/apk/res/android">     3.     <solid android:color="#ffffff" />     
4.     <stroke android:width="3dp" color="#000000" />     5.     <corners android:radius="3dp" />     
6.     <padding android:left="3dp" android:top="3dp" android:right="3dp"     7.         android:bottom="3dp" />   8. 
</shape>    
view plaincopy to clipboardprint? 
1. <?xml version="1.0" encoding="utf-8"?>  <shape xmlns:android="http://schemas.android.com/apk/res/android">      <
solid android:color="#ffffff" />      <stroke android:width="3dp" color="#000000" />      <corners android:radius="3dp" />      <padding android:left="3dp" android:top="3dp" android:right="3dp"          android:bottom="3dp" /></shape>    
<?xml version="1.0" encoding="utf-8"?>  <shape xmln
   
再在res/values/下建styles.xml,设置程序的风格 
view plainprint? 
1. <?xml version="1.0" encoding="utf-8"?>     2. <resources>   
3.         <!-- 设置样式 -->

4.     <mce:style name="Theme.MyActivity" parent="android:style/Theme.Dialog" mce_bogus="1" mce_bogus="1"><!--  
5.         <item name="android:windowBackground">@drawable/bgconfig</item>  6.       
7. --></mce:style><style name="Theme.MyActivity" parent="android:style/Theme.Dialog" mce_bogus="1" mce_bogus=
"1" mce_bogus="1">     <item name="android:windowBackground">@drawable/bgconfig</item>   8.     </style>   9. </resources>   
view plaincopy to clipboardprint? 
1. <?xml version="1.0" encoding="utf-8"?>  <resources>        <!-- 设置样
式 --><mce:style name="Theme.MyActivity" parent="android:style/Theme.Dialog" mce_bogus="1" mce_bogus="1"><!--<item name="android:windowBackground">@drawable/bgconfig</item>--></mce:style><style name="Theme.MyActivity" parent="android:style/Theme.Dialog" mce_bogus="1" mce_bogus="1" mce_bogus="1">        <item name="android:windowBackground">@drawable/bgconfig</item></style></resources>   
<?xml version="1.0" encoding="utf-8"?>  <resources>
 
注:mce部分为发帖是自动生成的,实际不需要。 
最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任意<activity>标签中添加  
android:theme = "@style/transparent"  
如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在<application>中。   
3.设置窗口大小和位置 
view plainprint? 
1. WindowManager m = getWindowManager();     
2.        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高     3.

4.        LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值     5.        p.height = (int) (d.getHeight() * 1.0);   //高度设置为屏幕的1.0    6.        p.width = (int) (d.getWidth() * 0.7);    //宽度设置为屏幕的0.8    7.        p.alpha = 1.0f;      //设置本身透明度   8.        p.dimAmount = 0.0f;      //设置黑暗度   9.             
10.        getWindow().setAttributes(p);     //设置生效   
11.        getWindow().setGravity(Gravity.RIGHT);       //设置靠右对齐

Android中自定义Activity和Dialog的位置大小背景和透明度等的更多相关文章

  1. Android中自定义Activity和Dialog的位置大小背景和透明度等demo

    1.自定义Activity显示样式 先在res/values下建colors.xml文件,写入: <?xml version="1.0" encoding="utf ...

  2. 在Android中动画移动一个View的位置,采用Scroller类实现Android动画之 View移动

    在Android中动画移动一个View的位置,采用Scroller类实现 今天说最近自己遇到的一个问题,就是要用动画效果来移动一个VIew的位置. 这个具体的情况是,需要做一个SlidingMenu的 ...

  3. Android中半透明Activity效果另法

    Android中的Activity有没有类似于像Windows程序样的窗口式显示呢? 答案当然是有. 下图就是一个窗口式Activity的效果图: 下面就说说实现过程: 首先看看AndroidMani ...

  4. [转]Android中自定义checkbox样式

    android中自定义checkbox的图片和大小   其实很简单,分三步: 1.在drawable中创建文件checkbox_selector.xml: <?xml version=" ...

  5. 转--Android中自定义字体的实现方法

    1.Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace 2.在Android中可以引入其他字体 . 复制代码 代码如下: <?xml versio ...

  6. Android中自定义veiw使用Java中的回调方法

    //------------------MainActivity----中---------------------------------- import android.os.Bundle;imp ...

  7. Android中的Activity

    Android四大组件 活动(Activity) 广播接收者(BroadCastReceiver) 服务(Service) 内容提供者(Contentprovider) Activity 先来看And ...

  8. Android中自定义组合控件

    Android中自定义控件的情况非常多,一般自定义控件可以分为两种:继承控件及组合控件.前者是通过继承View或其子类,重写方法实现自定义的显示及事件处理方式:后者是通过组合已有的控件,来实现结构的简 ...

  9. Android中自定义ListView实现上拉加载更多和下拉刷新

    ListView是Android中一个功能强大而且很常用的控件,在很多App中都有ListView的下拉刷新数据和上拉加载更多这个功能.这里我就简单记录一下实现过程. 实现这个功能的方法不止一个,Gi ...

随机推荐

  1. 【转】 分析iOS Crash文件:符号化iOS Crash文件的3种方法

    当你的应用提交到AppStore或者各个渠道之后,请问你多久会拿到crash文件?你如何分析crash文件的呢? 上传crash文件 你的应用应当有模块能够在应用程序crash的时候上传crash信息 ...

  2. 集成支付宝后出现LaunchServices: ERROR: There is no registered handler for URL scheme alipay

    原因如下: There's no problem with your implementation. All those warnings mean is the apps which each UR ...

  3. This system is not registered with RHN解决方法

    root@localhost ipvsadm-1.25]# yum install gcc Loading "security" plugin Loading "rhnp ...

  4. cas配置全攻略(转)

    转:http://www.blogjava.net/tufanshu/archive/2011/01/21/343290.html 经过将近两天的测试,参考众多网友的贡献,终于完成了对cas的主要配置 ...

  5. [转]C++基本功和 Design Pattern系列 ctor & dtor

    今天Aear讲的是class.ctor 也就是constructor, 和  class.dtor, destructor. 相信大家都知道constructor 和 destructor是做什么用的 ...

  6. Linux下python3与python3的多版本共存

    python3已经出来有些许时候了,python3相比python2进行了大量的改进,包括语法,新的功能,还有优化.虽然很多库已经同时支持 python2和python3了,但是有些库仍然没有很好的支 ...

  7. 周赛D题

    D - D Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description ...

  8. PHP之路——MySql查询语句

    1,select查询的基本结构 select 字段 from 表 where 过滤条件 group by 分组条件 having 过滤的第二条件 order by 排序条件 limit 限定结果条件; ...

  9. JS和正则表达式验证手机号码、邮箱等

    <-------------------------------------验证手机号码---------------------------------------------> fun ...

  10. memcpy函数的使用方法

    c和c++使用的内存拷贝函数,memcpy函数的功能是从源src所指的内存地址的起始位置开始拷贝n个字节到目标dest所指的内存地址的起始位置中. 1.函数原型 void *memcpy(void * ...