日期:2014-05-17  浏览次数:20583 次

Android(六)通知、样式、主题、HTML
一、Android中的通知

         一般手机上边都有一个状态条,显示电池电量、信号强度、未接来电、短信...。Android的屏幕上方也具有状态条。这里所说的通知,就是在这个状态条上显示通知。



       发送通知的步骤如下:

       1).获取通知管理器

       NotificationManager mNotificationManager = (NotificationManager)        getSystemService(Context.NOTIFICATION_SERVICE);

       2).新建一个通知,指定其图标和标题

       int icon = android.R.drawable.stat_notify_chat;

       long when = System.currentTimeMillis();

       //第一个参数为图标,第二个参数为标题,第三个为通知时间

       Notification notification = new Notification(icon, null, when);

       Intent openintent = new Intent(this, OtherActivity.class);

       //当点击消息时就会向系统发送openintent意图

       PendingIntent contentIntent = PendingIntent.getActivity(this, 0, openintent, 0);

       notification.setLatestEventInfo(this, “标题”, “内容", contentIntent);

       mNotificationManager.notify(0, notification);



二、Android中的样式和主题

       android中的样式和CSS样式作用相似,都是用于为界面元素定义显示风格,它是一个包含一个或者多个view控件属性的集合。如:需要定义字体的颜色和大小。



       1).在values目录下添加styles.xml:

<?xml version="1.0" encoding="utf-8"?>

<resources>

         <style name="changcheng">

                   <item name="android:textSize">18px</item>

        <item name="android:textColor">#0000CC</item>

         </style>

</resources>



       2).在layout文件中可以通过style或 theme属性设置样式或主题。



三、使用HTML做为UI

       使用LayoutUI比较麻烦,不能让美工参与进来,这样就为开发人员带来了麻烦。但我们可以通过HTML+JS来进行UI的设计与操作。



       1).在assets添加Html页面

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>联系人列表</title>

<script type="text/javascript">

         function show(jsondata){

                   var jsonobjs = eval(jsondata);

                   var table = document.getElementById("personTable");

                   for(var y=0; y<jsonobjs.length; y++){

                 var tr = table.insertRow(table.rows.length); //添加一行

                 //添加三列

                 var td1 = tr.insertCell(0);

    &nbs