一:Notification

1.NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

2. notification.setLatestEventInfo(this, "国安部给你发短信!", "你被通辑啦~~~", contentIntent);

2.1: PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

2.1.1: Intent intent = new Intent();

intent.setAction(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:110"));

3.nm.notify(0,notification);

3.1:Notification notification = new

Notification(R.drawable.ic_launcher,"有新的消息到来了",System.currentTimeMillis());

4.为避免成为流氓软件,要: notification.flags = Notification.FLAG_AUTO_CANCEL;

详细代码:

  1. public class MainActivity extends Activity {
  2. private NotificationManager nm;
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.activity_main);
  6. nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  7. }
  8. // 通知是显示在一个系统应用里面的, 如果系统应用ui挂了,通知就不会出来了。
  9. public void click(View view) {
  10. @SuppressWarnings("deprecation")
  11. Notification notification = new
  12. Notification(R.drawable.ic_launcher,"有新的消息到来了",System.currentTimeMillis());
  13. notification.flags = Notification.FLAG_AUTO_CANCEL;
  14. //       //延期的意图,不是立刻执行的意图,最终这个意图是在另外一个应用程序里面执行
  15. Intent intent = new Intent();
  16. intent.setAction(Intent.ACTION_CALL);
  17. intent.setData(Uri.parse("tel:110"));
  18. PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
  19. //旧的api,一定要记得设置notification这一个参数
  20. notification.setLatestEventInfo(this, "国安部给你发短信!", "你被通辑啦~~~", contentIntent);
  21. nm.notify(0,notification);
  22. }
  23.   }

运行结果:

二:样式:style(只能作用在控件上)

1.在res/values/styles.xml设置样式

<style name="text_content_style">

<!-- item里面是键值对! -->

<item name="android:layout_width">wrap_content</item>

<item name="android:layout_height">wrap_content</item>

<item name="android:textColor">#FF0000</item>

<item name="android:textSize">20sp</item>

</style>

继承形式一

<style name="text_title_style" parent="@style/text_content_style">

<item name="android:textSize">30sp</item>

</style>

继承形式二

<style name="text_subtitle_style" parent="@style/text_content_style">

<item name="android:textSize">25sp</item>

</style>

2.使用样式:

<TextView

style="@style/text_title_style"

android:text="我是标题"/>

<TextView

style="@style/text_subtitle_style"

android:text="我是sub标题"/>

<TextView

style="@style/text_content_style"

android:text="我是文本"/>

3.效果图:

三:主题theme(作用在Activity或整个应用程序上Application)

1.在style.xml中配置:

参考:~\adt-bundle-windows-x86-20130729\sdk\platforms\android-16\data\res\values\themes.xml

第162行:Window attributes,可配置自己的Window attribute的主题。

注意:不同于系统的,自己要定义需要在name的字符串前加上:android:   如:

系统:

<item name="windowBackground">@android:drawable/screen_background_selector_dark</item>

自己:

<item name="android:windowBackground">@color/red</item>

<style name="red_theme">

<item name="android:windowBackground">@color/red</item>

</style>

2.在AndroidMainfest.xml中使用:

<activity

android:theme="@style/red_theme"

...

效果图:

Android下Notification,样式style,主题theme的功能实现的更多相关文章

  1. android中的样式和主题

    有的时候我们一个页面要用很多个textview,而且这些textview的样式非常相像,这种情况下我们可以把这些样式抽取出来,然后在每个textview中引用即可,这样修改起来也方便. 我们来看一个简 ...

  2. 【Android】attr、style和theme

    一.Attr 属性,风格样式的最小单元: Attr 的定义 在自定义 View 的时候,在 res/attrs.xml 文件中声明属性,而Android 系统的属性也是以同样的方式定义的.比如 lay ...

  3. Android零碎知识之Style and Theme

    Android的styles资源文件中存在了我们在应用中定义的各种style,它们都是以style开始的元素,包含许多属性的集合.但我们一般般它们分为style和theme,那它们有什么区别呢? 一. ...

  4. android下的样式

    android中控件,假如我们把样式都写死在控件的配置文件上的话.一旦改动可谓牵一发而动千军.那么我们能够把样式写在style.xml文件里.然后引用,在API14以上版本号. 该文件位于values ...

  5. [android] 安卓自定义样式和主题

    简单练习自定义样式和主题,样式是加在View上,主题是加在Application或者Activity上 styles.xml <?xml version="1.0" enco ...

  6. android UI进阶之style和theme的使用

    今天来和大家分享一下android中UI设计里面常会用到的style和theme. 首先,style和theme都是资源,android提供了很多这样的默认资源.你可以来使用它们.同时你也可以自己定义 ...

  7. ionic actionsheet在android下的样式问题

    https://forum.ionicframework.com/t/actionsheets-android-ugly-styling-need-help/18462/10 想要修改ionic的样式 ...

  8. Android 下拉刷新上拉载入效果功能

    应用场景: 在App开发中,对于信息的获取与演示.不可能所有将其获取与演示,为了在用户使用中,给予用户以友好.方便的用户体验,以滑动.下拉的效果动态载入数据的要求就会出现. 为此.该效果功能就须要应用 ...

  9. android 学习随笔十九(对话框、样式、主题、国际化 )

    1.对话框 package com.itheima.dialog; import android.os.Bundle; import android.app.Activity; import andr ...

随机推荐

  1. scoop - 初次使用

    scoop也是包管理工具,不过是含着金钥匙出生的(正巧碰上微软支持开源,并且拥抱开源生态圈),此后的Win10 powershell 3.x+也就不会像Win7 powershell 2.x那样沉默了 ...

  2. 微信小程序 - 组件传值给调用页面

    演示如下(可以ctrl+鼠标放大或者下载GIF图片) 1. 先组件定义事件“checkbox”(组件内事件) 2. 调用页面调用它需要加bind:事件名 = 调用页面事件名(bind即绑定调用组件“o ...

  3. 微信小程序 - 下拉菜单组件

    使用: 1.导入组件 2.使用组件 3.数据传入 4. 获取数据(通过同步缓存,获取“choose”)- 发送到后端 点击下载:小程序-下拉组件.

  4. 微软BI 之SSAS 系列 - 基于雪花模型的维度设计

    基于雪花模型的维度以下面的 Product 产品与产品子类别,产品类别为例. DimProduct 表和 DimProductSubcategory 表有外键关系,而 DimProductSubcat ...

  5. NGINX源码分析——概览

    一.概况 Nginx可以开启多个进程,每个进程拥有最大上限128个子线程以及一定的可用连接数.最大客户端连接数等于进程数与连接数的乘积,连接是在主进程中初始化的,一开始所有连接处于空闲状态.每一个客户 ...

  6. JavaScript的valueOf和toString

    深度好文 http://www.cnblogs.com/coco1s/p/6509141.html 知识要点 不同对象调用valueOf和toString的顺序不一样 高阶函数的使用,替代for循环 ...

  7. Java 基础【16】 文件(文件夹) 创建和删除

    使用 java.io.file 创建文件(文件夹),算是 java 最基础的知识,但实战项目中还是需要知晓细节. 比如 File 类中的 mkdir() 和 mkdirs() 的区别. JDK API ...

  8. ORA-00942 表或视图不存在

    场景:跨scheme创建视图,提示ORA-00942 表或视图不存在 1. 创建两个用户 CREATE USER ODI_SRC IDENTIFIED BY ODI_SRC CREATE USER O ...

  9. 【shell】各种括号()、(())、[]、[[]]、{}的使用

    圆括号 1.单圆括号() ①命令组,括号中的命令将会开启一个子shell独立运行:括号中以分号连接,最后一个命令不需要;各命令和括号无需空格 Linux:/qins # (var=1;echo $va ...

  10. How to use, monitor, and disable transparent hugepages in Red Hat Enterprise Linux 6

    Resolution Note: Transparent Huge Pages are not available on the 32-bit version of RHEL 6. Transpare ...