- 浏览: 41271 次
- 性别:
- 来自: 济南
最新评论
-
kensunhu:
正是我想要的。典型的app ui布局。谢谢!
android UI - 仿威信tab样式 -
007007jing:
bing_zz 写道兄弟加油!谢谢
android2.3 api demo 学习系列(7)--App/Activity/Hello World -
bing_zz:
兄弟加油!
android2.3 api demo 学习系列(7)--App/Activity/Hello World
apidemos里面展示的自定义窗口其实并不复杂,下面我们来看一下:
1、CustomDialogActivity和别的activity并没有区别
2、activity在项目AndroidManifest.xml配置文件中加入 android:Theme属性 例如示例:
<activity android:name=".app.activity.CustomDialogActivity" android:label="@string/app_activity_custom_dialog_lable" android:theme="@style/Theme.CustomDialog"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="com.angie.apidemos.SAMPLE_CODE" /> </intent-filter> </activity>
3、接下来就是创建theme Theme.CustomDialog。定义Theme 和定义Style 一样, 必须定义在/res/values 子目录下,
根元素名为resources,Theme 和Style 的区别在于Theme 应用于Activity 和Application 而 Style 应用于单个的View。
其定义方法是一致的。Style 定义支持 Inheritance, 也就是在定义新风格时可以基于系统定义的风格或是之前定义的风格: 如Theme.CustomDialog 定义就是基于Android 的Dialog 风格(parent)而只修改的WindowsBackground 属性,使用了褐色背景。
定义的theme如下:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme.CustomDialog" parent="android:style/Theme.Dialog"> <item name="android:windowBackground">@drawable/app_activity_custom_dlg_filled_box</item> </style> </resources>
其中引用了drawable里面的xml文件 其定义的是具体的样式 例如:
<?xml version="1.0" encoding="utf-8"?> <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>
效果如如下:
SDK中关于Styles and Themes的说明:
样式是规定 VIew和window显示样式的集合. 样式可以指定的属性: height, padding, font color, font size, background color等等.在layout XML文件中我们经常见到下面的定义:
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#00FF00" android:typeface="monospace" android:text="@string/hello" />
同样我们可以把textview的样式属性单独定义带CodeFont.xml中,在layout中引用如下:
<TextView style="@style/CodeFont" android:text="@string/hello" />
主题(theme)是应用到整个 Activity
或者 application的样式, 不是指单个view的样式定义. 如果将一个样式作为主题使用,那么在Activity或者application中得每一个view都会被主题样式影响。比如:CodeFont作为主题应用到Activity或者application,Activity或者application中得text都会变成green monospace font
定义Styles
styles的定义文件xml必须保存于 项目res/values/ 中,
并且文件的根节点必须是
<resources>,类似的定义如下
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CodeFont" parent="@android:style/TextAppearance.Medium"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#00FF00</item> <item name="android:typeface">monospace</item> </style> </resources>
注:theme的定义和style一样,主要是看你将其应用在view上还是activity或者application上;
同时style的定义支持继承,例如我们定义一个新的style继承自系统已有的style
<style name="GreenText" parent="@android:style/TextAppearance"> <item name="android:textColor">#00FF00</item> </style>
新的GreenText继承自系统已有style TextAppearance,只是修改了文字的颜色。
需要格外注意的是:我们继承系统已有style的时候使用了关键字parent,但是如果需要继承我们自己定义的style的时候就不能使用parent关键字了,sdk中介绍使用 点 举例说明:继承我们自己定义的CodeFont style
<style name="CodeFont.Red"> <item name="android:textColor">#FF0000</item> </style>
新的style在使用的时候可以直接使用:@style/CodeFont.Red. 我们可以继续继承新的style来定义style:
<style name="CodeFont.Red.Big"> <item name="android:textSize">30sp</item> </style>
新的style继承了CodeFont
和 CodeFont.Red
的所有属性,并且新定义的字体大小属性。
特别强调:这种使用小数点方式的继承机制只使用于自定义的资源,如果使用android内置的style或者theme必须使用关键字parent。
关于style properties建议参考sdk中每个view class 。里面有详细的说明该view支持的属性。
关于已定义的style引用详细清单请参考sdk中得R.attr。其中以window开头的引用只使用与主题(theme),不适用任何一个view。例如 windowBackground
等;
接下来我们举例说明style和theme的用法
1.view element
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#00FF00" android:typeface="monospace" android:text="@string/hello" />
2.view使用已有style
<TextView style="@style/CodeFont" android:text="@string/hello" />
3.将theme应用到activity或者application
<application android:theme="@style/CustomTheme">
<activity android:theme="@android:style/Theme.Dialog">
如果系统的theme并不完全适用于项目,可以像下面这个样子修改theme
<color name="custom_theme_color">#b0b0ff</color> <style name="CustomTheme" parent="android:Theme.Light"> <item name="android:windowBackground">@color/custom_theme_color</item> <item name="android:colorBackground">@color/custom_theme_color</item> </style>
然后再使用:
<activity android:theme="@style/CustomTheme">
Select a theme based on platform version
如果想根据不同的平台版本选择主题,加入我们想规定Android 3.0 (API Level 11)或者更高的版本的主题,则可以定义theme.xml 保存在/res/values-v11 文件夹内。
<style name="LightThemeSelector" parent="android:Theme.Holo.Light"> ... </style>
注意parent引用的时候使用的引用名称为全称。
至此我们简单的了解了android的style和theme 更多详细的内容大家还是参考sdk中得说明。谢谢
发表评论
-
android2.3 api demo 学习系列(23)--App/Notification/StatusBarNotification
2012-07-07 19:51 1301apidemo-StatusBarNotification里面 ... -
android2.3 api demo 学习系列(22)--App/Notification/Notifying Service Controller
2012-07-06 14:56 1674因为还没有看到service的demo,这里先不对servic ... -
android2.3 api demo 学习系列(21)--App/Notification/Incoming Message
2012-07-06 11:55 2428现在我们开始学习android的Status Bar Noti ... -
android2.3 api demo 学习系列(20)--App/Menu
2012-07-06 09:58 1114现在来学习下menu的相关 ... -
android2.3 api demo 学习系列(19)--App/Intent and Launcher Shortcuts
2012-07-06 09:36 1063第一个demo:Intent,根据指定的类型,枚举出所有符合条 ... -
android2.3 api demo 学习系列(18)--App/Dialog
2012-07-06 09:13 958今天主要学习Dialog: 1、一般的dialog ... -
android2.3 api demo 学习系列(17)--App/Alarm/AlarmController and Alarm Service
2012-07-03 17:12 2146本次学习将apidemo中得两个demo:AlarmContr ... -
android2.3 api demo 学习系列(16)--App/Activity/Translucent and Blur activity
2012-07-03 11:47 1855本次同样是将apidemo中得两个demo合并起来学习:Tra ... -
android2.3 api demo 学习系列(15)--App/Activity/SetWallpaper
2012-07-03 11:00 1092本次示例我们整合了apidemo里面的两个demo:SetWa ... -
android2.3 api demo 学习系列(14)--App/Activity/Screen Orientation
2012-07-03 09:50 3081下面我们来学习下Screen Orientaiton的demo ... -
android2.3 api demo 学习系列(13)--App/Activity/Save & Restore
2012-07-02 17:29 1437前面文章android2.3 api demo 学习系 ... -
android2.3 api demo 学习系列(12)--App/Activity/Reorder Activitys
2012-07-02 16:45 960Reorder Activitys Demo主要是实现打开ac ... -
android2.3 api demo 学习系列(11)--App/Activity/Redirection
2012-07-02 15:52 831APIDEMO里面的redirection示例本身并没有新技术 ... -
android2.3 api demo 学习系列(10)--App/Activity/RecevieResult
2012-07-02 14:48 959在先前的文章 activity之间跳转传值 已经学习过这方面的 ... -
android2.3 api demo 学习系列(9)--App/Activity/QuickContactsDemo
2012-07-01 19:46 959现在我们来学习如何使用Content Provider来访问a ... -
android2.3 api demo 学习系列(8)--App/Activity/Preference State
2012-07-01 19:45 870android保存数据有很多种方式,其中最简单的就是使用Sha ... -
android2.3 api demo 学习系列(7)--App/Activity/Hello World
2012-06-29 14:03 1049学习android当然不能少了HelloWorld,接下来我们 ... -
android2.3 api demo 学习系列(6)--App/Activity/ForwardActivity
2012-06-29 13:50 799本次学习activity的跳转 1、构建intent ... -
android2.3 api demo 学习系列(5)--App/Activity/Dialog
2012-06-29 11:42 970前面我们已经学习了Custom Dialog 和 Custom ... -
android2.3 api demo 学习系列(4)--App/Activity/Custom Title
2012-06-29 11:26 1055android的标题栏默认是由android:lable定义的 ...
相关推荐
android dialog-------普通对话框
implementation 'moe.shizuku.preference:preference-dialog-android:' //implementation 'moe.shizuku.preference:preference-dialog-appcompat:' // if you want to use appcompat version dialog //...
AppUpdater for Android 是一个专注于App更新一键傻瓜式集成的开源库,主要包括app-updater和app-dialog。 > 下载更新和弹框提示分开,是因为这本来就是两个逻辑。完全独立开来能有效的解耦。 app-updater 主要负责...
* 本js只是在bootstrap3-dialog的基础上进行的2次封装, * bootstrap3-dialog已经是非常好用了,调用也非常简单。 * 详情请访问:https://github.com/nakupanda/bootstrap3-dialog, * 这是原项目地址,可以自行...
React Native Android Location Services对话框 从Android位置服务打开对话框的React-Native组件安装大多是自动安装(推荐) yarn add react-native-android-location-services-dialog-box 要么npm install react-...
<el-dialog :visible.sync="visible" title="Hello world"> <p>Try Element</p> </el-dialog> </div> <el-button type="primary" icon="el-icon-search">搜索</el-button> <!-- import Vue before Element -...
Android---UI篇---Dialog(对话框)
Android自定义dialogDemo
Dialog 很经常用到的一个控件,但大多时候系统默认的样式是不满足于项目使用的,故自定义了一套合适的Dialog模板方便日常使用。
A simple to use library to create a android L dialog on any 2.3 android device in your app using 3 Lines of code! How to compile the example Download the zip Extract Import with android studio ...
vue-dialog-drag简单的可拖动对话框演示功能:拖放支持(仅用于拖放,不用于拖放)拖放区域组件“ Pin模式”,以锁定vue-dialog-drag简单的可拖动对话框演示功能:拖放支持(仅用于拖动,不用于放置)放置区域组件...
You'll need something that handles "org.openintents.action.PICK_FILE" ....Install my app: ...- Tap "Load" text to open an open file dialog. Pick a SMF file. -
Simple Android Library that provide you a custom dialog that allow you to set a start time and end time. Screenshot Install Add this to your project build.gradle allprojects { ...
API对话框------Win32 DialogBased Application插件的安装
在Android开发中,我们经常会需要在android界面上弹出一些对话框,比如询问用户或者让用户选择。,但是只是给出了创建各种类型对话框的方法,并未给出如何获取用户在对话框中做出选择后的数据,即如何监听用户做出的...
本例中,包含DialogDemo(Dialog/app/)是对话框的演示项目源代码,以及Library库(Dialog/dialog/)是封装的空祖家对话框的源代码。 项目托管的Maven仓库在https://bintray.com/myzchh/maven/dialog 本项目遵循...
Material color chooser dialog; Save colors to storage; Round icon support for android 7.1; The app supports 4.1 devices. You can download the latest (3.0.6) signed APK from this repo here: ...
jquery 弹出窗口插件,包含js中的 alert confirm open 等。
Dialog Vue 的 Dialog 弹窗组件,包含了 alert 和 confirm 对话框。 参考代码: Use npm install vue-m-dialog import MDialog from 'vue-m-dialog' // ro import { Dialog, Alert, Confirm } from 'vue-m-dialog' ...
Activity替代dialog的demo,Activity替代dialog的demo,Activity替代dialog的demo