Android中自定义Activity和Dialog的位置大小背景和透明度等
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); //设置靠右对齐
最新文章
- 【记录】xUnit for vs2012/vs2013
- js获取事件源
- Ubuntu配置Open BlockChain
- 【springBoot】springBoot集成redis的key,value序列化的相关问题
- SpringMVC 的 Controller 返回各种视图的处理方式
- C#之多态
- UVa 10054 The Necklace【欧拉回路】
- IE-“无法浏览网页” 教你十招解决疑难杂症
- freewrap——将tcl/tk脚本转变为可执行文件
- 什么是 CSS 预处理器?
- CI框架浅析(二)
- JavaScript 基本语法 -- 运算符的优先级
- NSURLSession http转Https
- eclipse中生成的html存在中文乱码问题的解决方法
- Easyui datagrid 设置内容超过单元格宽度时自动换行显示
- jmeter启动报错
- 使用docker部署springboot
- MySql 引擎
- 使用arguments对象验证函数的参数是否合法
- Ulua_toLua_基本案例(八)_LuaAccessingArray
热门文章
- 解决第三方DLL没有强签名
- class-loader.
- JNI type
- Solution(项目部署):The server does not support version 3.0 of the J2EE Web module specification
- zookeeper集群一次性启动
- Android入门随记
- delphi 创建数据库配置文件(TIniFile)
- How to create Managed Metadata Column
- bzoj1115: [POI2009]石子游戏Kam
- nil、Nil、NULL与NSNull的区别--备用