打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android API Demo研究(1) - 编程 - goandroid
Android API Demo研究(1)
1. Custom Dialog
Android支持自定义窗口的风格:
1)首先在资源里面建立style的value;
example:
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/filled_box</item>
</style>
drawable/filled_box.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f0600000"/>
<stroke android:width="3dp" color="#ffff8080"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
PS:关于Styles的学习,可以参见:http://code.google.com/android/reference/available-resources.html#stylesandthemes
2)设置当前activity的属性,两种方式:1.在manifest文件中给指定的activity增加属性
android:theme="@android:style/Theme.CustomDialog"。2.在程序中增加语句setTheme(R.style.Theme_CustomDialog);
PS1:如果只是将Acticity显示为默认的Dialog, 跳过第一步,只需要在manifest文中增加属性:android:theme="@android:style/Theme.Dialog"或者在程序中增加setTheme(android.R.style.Theme_Dialog).
PS2:其他创建Dialog的方法:创建app.Dialog类或者创建app.AlertDialog类。
Next Study:能不能在Activity已经打开以后动态修改当前Activity的风格?
在测试中发现,在onCreate()事件中增加setTheme(),必须在setContentView()之前,否则指定的Style不能生效
2.Custom Title
Android除了可以为指定的Activity设置显示风格,此外也可以为指定的Activity设置一些特效,比如自定义Title,没有Title的Activity或者增加一个ICON等。
有意思的一点是,这些特效并不是你想设置的时候就行设置,你需要在Activity显示之前向系统申请要显示的特效,这样才能在下面的程序中为这些特效进行设置。(这样是不是多此一举有待研究)
为一个Activity设置自定义Title的流程:
1)为自定义的Title建立一个layout(custom_title_1.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Left" />
<TextView android:id="@+id/right_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Right" />
</RelativeLayout>
关于为什么采用RelativeLayout,可以参见:http://code.google.com/android/devel/ui/layout.html
2)为activity设定自定义Title特效并指定Title的layout:
在onCreate()事件中增加:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
这三条语句的次序不能颠倒,依次为申请特效,创建view,设置特效属性。其中requestWindowFeature等价于getWindow().requestFeature()
3)在需要修改Title的地方,获取left_text或者right_text进行设置即可。
Next Study:Activity的其他显示特效
Window还有其他一些feature,比如FEATURE_CONTEXT_MENU,FEATURE_NO_TITLE,FEATURE_LEFT_ICON等,有待继续学习研究。
原文地址http://zxshean.spaces.live.com/blog/
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
不懂记, 如何利用Activity的Dialog风格完成弹出框设计——day6
android 悬浮球的实现
android activity的叠加启动
去掉Activity中titleBar
Android教程(2.1) Activity的详细讲解 - Haric的程序空间 - J...
去掉android的屏幕上的title bar
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服