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. Ext checkbox

    Ext.require([     'Ext.grid.*',     'Ext.data.*',     'Ext.util.*',     'Ext.grid.PagingScroller',   ...

  2. 数据逆向传递 unwind segue

    一.简介 unwind segue通过允许你定义一个控制器和其他控制器的关系来扩展segue的概念,这个“关系”先于顺传(流式控制)的方式.基于unwind segue可以实现导航相反的效果,即将界面 ...

  3. c - 折半查找(二分法检索)

    #include <stdio.h> #define LEN 10 /* 折半查找(二分法检索). */ int index_of(int *a, int k) { ; ; int m; ...

  4. WebService笔记-Schema约束

                        Schema约束 俗话说得好 好记性不如烂笔头. 看了下WebService视频,觉得还是得下笔记. 观看的视频地址:http://edu.51cto.com/ ...

  5. 如果使用的是orm,是否还需要关系索引

    简而言之:是的,仍然需要理解索引,即使是使用对象关系映射(ORM)工具. ORM工具能够产生符合逻辑的,合法的查询(多数的时候),除非只是生成非常基本的查询(例如仅是根据主键查询的),否则它很难生成适 ...

  6. C# .net 如何根据访问者IP获取所在地区

    第一步:在根目录添加新项(类),新建一个类文件,把以下文件粘贴到该类文件下:   using System; using System.Collections.Generic; using Syste ...

  7. 使用grunt压缩css是能否设置background-size不压缩进去呢?否则ie8不能识别

    .index-bg{ background:url(img/index-bg-t.5344b19d.jpg) center center/cover no-repeat } 比如上面这样ie8不能识别 ...

  8. 大脑皮层是如何工作的 《人工智能的未来》(<On intelligence>)读书笔记

    PS:今年寒假的读书笔记,挖下的坑已无力再填...不过有关智能和人工智能的书还是要继续读的~ 正文: 我觉得书名翻译不是很确切,全书讨论的核心应该更是在“真”智能:讨论对人脑智能的理解,可以怎样帮助我 ...

  9. python的sorted相关

    Python 字典排序 在python里,字典是内置的数据类型,是个无序的存储结构,每一个元素是key-value对: 有关key的解释: sorted(L,key=by_name)中的key即by_ ...

  10. sphinx,github和readthedocs配合使用

    http://daler.github.io/sphinxdoc-test/includeme.html http://pages.github.com/ http://www.lulinfeng.c ...