• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > Android5.0开发范例大全 读书笔记(六),android5.0范例

Android5.0开发范例大全 读书笔记(六),android5.0范例

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了android5.0,android5.0新特性,android5.0系统下载,android5.0模拟器,android5.0系统手机等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android5.0开发范例大全 读书笔记(六),android5.0范例


(六)与系统交互

6.1后台通知

1.关于后台通知,下面展示6种样式。值得一提的是,笔者的小米5只能显示基本样式,雷军真是良心厂商啊。

2.首先上布局xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/options_group">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rich Styles"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/option_basic"
            android:text="Basic Notification"
            android:checked="true"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/option_bigtext"
            android:text="BigText Style"
            />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/option_bigpicture"
            android:text="BigPicture Style"
            />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/option_inbox"
            android:text="Inbox Style"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="Secured Styles"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/option_private"
            android:text="Public Version LockScreen" />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/option_secret"
            android:text="Secret LockScreen" />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/option_headsup"
            android:text="Heads-Up Notification" />
    </RadioGroup>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Post a Notification"
        android:onClick="onPostClick"/>
</LinearLayout>

3.接着是完整代码

ublic class NotificationActivity extends AppCompatActivity {
    private RadioGroup mOptionsGroup;
    private static Handler mHandle = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification);
        mOptionsGroup = (RadioGroup) findViewById(R.id.options_group);

    }

    public void onPostClick(View view) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        final int noteId = mOptionsGroup.getCheckedRadioButtonId();
        Notification note = null;
        switch (noteId) {
            case R.id.option_basic:
            case R.id.option_bigtext:
            case R.id.option_bigpicture:
            case R.id.option_inbox:
                note = buildStyledNotification(noteId);
                break;
            case R.id.option_private:
            case R.id.option_secret:
            case R.id.option_headsup:

                note = buildSecuredNotification(noteId);
                break;
        }
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(noteId, note);
    }

    private Notification buildStyledNotification(int type) {
        Intent launchIntent = new Intent(this, NotificationActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(NotificationActivity.this);
        builder.setSmallIcon(R.mipmap.ic_launcher)
                .setTicker("something happen")
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setContentTitle("we are finished")
                .setContentText("click here")
                .setContentIntent(contentIntent)



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android 5.0(包含5.0以下版本) 获取栈顶应用程序包名,android包名
  • Android5.0开发范例大全 读书笔记(五),android5.0范例
  • Android5.0开发范例大全 读书笔记(六),android5.0范例
  • Android5.0开发范例大全 读书笔记(三),android5.0范例
  • Android5.0开发范例大全 读书笔记(四),android5.0范例
  • android 5.0后对于apk 跑32 64 的逻辑
  • Android 5.0 Settings源码简要分析
  • Android5.0新特性-Material Design
  • Android5.0之Toobar的使用
  • Android 6.0 系统棉花糖新的特性和功能

相关文章

  • 2017-05-26VMware中ubuntu忘记密码的解决办法(转)
  • 2017-05-26Android仿联系人列表分组悬浮列表实现,自定义PinnedHeaderListView实现
  • 2017-05-26android 5.X Toolbar+DrawerLayout实现抽屉菜单
  • 2017-05-26Android触摸事件(三)-触摸事件类使用实例
  • 2017-05-26Android ExpandableListView相关介绍
  • 2017-05-26XAMARIN ANDROID 二维码扫描示例,xamarinandroid
  • 2017-05-26PostgreSql数据库的神器 FDW
  • 2017-05-26android:使用gallery和imageSwitch制作可左右循环滑动的图片浏览器
  • 2017-05-26一起来学习Android自定义控件
  • 2017-05-26HBase Thrift2 CPU过高问题分析

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android Studio 优秀插件(二): Parcelable Code Generator,androidparcelable
    • Android 在Activity页面中如何实现Fragment数据的缓加载
    • Android中使用SDcard进行文件的读取,androidsdcard
    • andriod CheckBox,andriodcheckbox
    • 踩坑实录 Android studio中关于 No cached version of **** available for of处理办法,androidcached
    • 重写dispatchKeyEvent方法 按返回键back 执行两次的解决办法,dispatchkeyevent
    • Android开发学习——打电话应用,android开发打电话
    • Android 手机卫士--导航界面1的布局编写,android卫士
    • Kerberos简介
    • 初涉RxAndroid结合Glide实现多图片加载操作

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有