package com.example.administrator.myapplication;import androID.provIDer.Settings;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.annotation.TargetAPI;import androID.app.AlertDialog;import androID.app.Notification;import androID.app.notificationmanager;import androID.os.Build;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.ImageVIEw;import androID.Widget.linearLayout;import androID.Widget.Toast;public class MainActivity extends AppCompatActivity { private button normalToast, imagetoast; private button createNotify, deleteNotify; private int NOTIFICATION_ID = 0x123; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); normalToast = (button) findVIEwByID(R.ID.normalToast); imagetoast = (button) findVIEwByID(R.ID.imagetoast); createNotify = (button) findVIEwByID(R.ID.createNotify); deleteNotify = (button) findVIEwByID(R.ID.deleteNotify); // 显示普通文本Toast normalToast.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Toast.makeText(MainActivity.this, "普通的Toast信息", Toast.LENGTH_SHORT).show(); } }); // 显示自定义视图Toast imagetoast.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Toast toast = Toast.makeText(MainActivity.this, "带图片的Toast信息", Toast.LENGTH_SHORT); VIEw toastVIEw = toast.getVIEw(); ImageVIEw imageVIEw = new ImageVIEw(MainActivity.this); imageVIEw.setimageResource(R.mipmap.ic_launcher); linearLayout linearLayout = new linearLayout(MainActivity.this); linearLayout.setorIEntation(linearLayout.HORIZONTAL); linearLayout.addVIEw(imageVIEw); linearLayout.addVIEw(toastVIEw); toast.setVIEw(linearLayout); toast.show(); } }); createNotify.setonClickListener(new VIEw.OnClickListener() { @TargetAPI(Build.VERSION_CODES.JELLY_BEAN) @OverrIDe public voID onClick(VIEw v) { Notification.Builder builder = new Notification.Builder(MainActivity.this); builder.setSmallicon(R.mipmap.ic_launcher_round); builder.setTicker("Notification的提示测试"); builder.setContentTitle("Notification的标题测试"); builder.setContentText("Notification的内容测试"); builder.setWhen(Sy@R_404_6563@.currentTimeMillis()); Notification notification = builder.build(); notification.defaults = Notification.DEFAulT_SOUND; notificationmanager notificationmanager = (notificationmanager) getSy@R_404_6563@Service(NOTIFICATION_SERVICE); notificationmanager.notify(NOTIFICATION_ID, notification); } }); deleteNotify.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { notificationmanager notificationmanager=(notificationmanager) getSy@R_404_6563@Service(NOTIFICATION_SERVICE); notificationmanager.cancel (NOTIFICATION_ID); } }); }}
activity_main.xml<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" tools:context="com.example.administrator.myapplication.MainActivity"> <button androID:ID="@+ID/normalToast" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="普通Toast"/> <button androID:ID="@+ID/imagetoast" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="带图片Toast"/> <button androID:ID="@+ID/createNotify" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="创建消息"/> <button androID:ID="@+ID/deleteNotify" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="删除消息"/></linearLayout>
@H_419_27@
@H_419_27@
总结以上是内存溢出为你收集整理的消息组件的开发和使用全部内容,希望文章能够帮你解决消息组件的开发和使用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)