Android下Notification,样式style,主题theme的功能实现
一: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;
详细代码:
- public class MainActivity extends Activity {
- private NotificationManager nm;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- }
- // 通知是显示在一个系统应用里面的, 如果系统应用ui挂了,通知就不会出来了。
- public void click(View view) {
- @SuppressWarnings("deprecation")
- Notification notification = new
- Notification(R.drawable.ic_launcher,"有新的消息到来了",System.currentTimeMillis());
- notification.flags = Notification.FLAG_AUTO_CANCEL;
- // //延期的意图,不是立刻执行的意图,最终这个意图是在另外一个应用程序里面执行
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_CALL);
- intent.setData(Uri.parse("tel:110"));
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
- //旧的api,一定要记得设置notification这一个参数
- notification.setLatestEventInfo(this, "国安部给你发短信!", "你被通辑啦~~~", contentIntent);
- nm.notify(0,notification);
- }
- }
运行结果:
二:样式: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的功能实现的更多相关文章
- android中的样式和主题
有的时候我们一个页面要用很多个textview,而且这些textview的样式非常相像,这种情况下我们可以把这些样式抽取出来,然后在每个textview中引用即可,这样修改起来也方便. 我们来看一个简 ...
- 【Android】attr、style和theme
一.Attr 属性,风格样式的最小单元: Attr 的定义 在自定义 View 的时候,在 res/attrs.xml 文件中声明属性,而Android 系统的属性也是以同样的方式定义的.比如 lay ...
- Android零碎知识之Style and Theme
Android的styles资源文件中存在了我们在应用中定义的各种style,它们都是以style开始的元素,包含许多属性的集合.但我们一般般它们分为style和theme,那它们有什么区别呢? 一. ...
- android下的样式
android中控件,假如我们把样式都写死在控件的配置文件上的话.一旦改动可谓牵一发而动千军.那么我们能够把样式写在style.xml文件里.然后引用,在API14以上版本号. 该文件位于values ...
- [android] 安卓自定义样式和主题
简单练习自定义样式和主题,样式是加在View上,主题是加在Application或者Activity上 styles.xml <?xml version="1.0" enco ...
- android UI进阶之style和theme的使用
今天来和大家分享一下android中UI设计里面常会用到的style和theme. 首先,style和theme都是资源,android提供了很多这样的默认资源.你可以来使用它们.同时你也可以自己定义 ...
- ionic actionsheet在android下的样式问题
https://forum.ionicframework.com/t/actionsheets-android-ugly-styling-need-help/18462/10 想要修改ionic的样式 ...
- Android 下拉刷新上拉载入效果功能
应用场景: 在App开发中,对于信息的获取与演示.不可能所有将其获取与演示,为了在用户使用中,给予用户以友好.方便的用户体验,以滑动.下拉的效果动态载入数据的要求就会出现. 为此.该效果功能就须要应用 ...
- android 学习随笔十九(对话框、样式、主题、国际化 )
1.对话框 package com.itheima.dialog; import android.os.Bundle; import android.app.Activity; import andr ...
随机推荐
- HttpLuaModule——翻译(二)
access_by_lua access阶段.事例: location / { deny 192.168.1.1; allow ; allow ; deny all; access_by_lua ' ...
- 2016 博客导读总结 & 个人感悟
此文着笔之时.2017已经在眼前了.预计等我写完,2017已经到了. 二次编辑于2017年1月1日早11点. 关于2016的感悟.十二月初就想写,当时认为是有点太早了,只是却思绪如泉涌. 且那时候才刚 ...
- 算法笔记_202:第三届蓝桥杯软件类决赛真题(Java高职)
目录 1 填算式 2 提取子串 3 机器人行走 4 地址格式转换 5 排日程 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 填算式 [结果填空] (满分11分) 看这个算式: ☆☆☆ + ☆☆ ...
- web ide
https://www.jianshu.com/p/339dff3da1fa https://www.eclipse.org/che/ https://github.com/Coding/WebIDE ...
- Aerospike系列:5:安装AMC
1:需要安装的包,如果缺少,请安装. python (2.6+) gcc python-devel 安装相应的模块 sudo pip install markupsafe sudo pip insta ...
- JavaWeb分页显示内容之分页查询的三种思路(数据库分页查询)
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6134851.html 在开发过程中,经常做的一件事,也是最基本的事,就是从数据库中查询数据,然后在客户端显示出 ...
- 由一次 symbol lookup error 引发的思考
开发一个跨平台的项目的时候,大部分时候都是在VS下进行编码,所以也就使用了VS的解决方案来管理项目. 因为要跨平台,当时网上看scons这个工具不错,所以在linux下就使用了scons来作为编译脚本 ...
- vs code 问题:preLaunchTask“build”已终止,退出代码为 1。解决办法
菜单:任务-配置任务 改为如下: { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation ab ...
- 基于kettle8的web端调度监控平台
发布时间:2018-11-16 技术:spring+springmvc +beetlsql+quartz+kettle8 概述 Kettle调度监控平台(以下简称KS)是一个自主开发的java ...
- [转]GFS架构分析
Google文件系统(Google File System,GFS)是构建在廉价的服务器之上的大型分布式系统.它将服务器故障视为正常现象,通过软件的方式自动容错,在保证系统可靠性和可用性的同时,大大减 ...