`
soboer
  • 浏览: 1311678 次
文章分类
社区版块
存档分类
最新评论

Android_文档学习_UI_Notifying the User

 
阅读更多

Notifying the User

本文测试代码csdn下载频道:http://download.csdn.net/source/2907960

通知用户的方式包括3种.一种是Toast一种是Status Bar(状态栏),还有一种是前面已经提到过的Dialog(对话框).具体的我就不介绍了,因为网上也介绍的比较清楚.我就把怎么用的,然后使用过程中,需要注意到的一些写一下.这样读者读起来就比较轻松了.

1.Creating Toast Notifications

首先,要具体化一个Toast对象用makeText()方法.这个方法需要3个参数.包括应用程序的Context,text message,duration.然后才会返回一个具体化的Toast对象.你可以用show()方法,显示出Toast来.代码如下:

Toast效果图

你也可以将代码简化,用下面的代码:

用setGravity(int, int, int)方法,接收3个参数.改变Toast显示的位置.参数用户可以自己调试然后看效果.

代码如下:

Creating a Custom Toast View

创建自定义的Toast可以现在layout/目录下,建一个xml文件(如:toast_layout.xml):用如下代码自定义Toast

然后在java文件中写入如下代码:

步骤1,先用 getLayoutInflater() (或 getSystemService() )检索LayoutInflater,然后用inflate(int, ViewGroup)方法从xml文件中inflate布局.

步骤2,捕捉定义了的View对象(例子中是ImageView and TextView elements.)

步骤3,创建一个Toast,然后设置toast的一些属性.再调用setView(View)设置布局.最后调用show()方法.

注意:不要使用public构造方法,除非你将要用setView(View)方法 定义这个布局.如果你没有自定义的toast要用的话,你必须用 makeText(Context, int, int)创建一个Toast.

2.Creating Status Bar Notifications

1.先定义一个静态常量

然后在onCreate或者其他方法中写如下代码:2F

本文测试代码csdn下载频道:http://download.csdn.net/source/2907960

新手初学,希望写的不好的地方.或者我哪里理解错误的地方.同学们能帮我指出来,让我明白.

分享到:
评论

相关推荐

    Android_Notifying the User测试代码

    文章http://blog.csdn.net/Jason69181/archive/2010/12/14/6074895.aspx测试代码

    Android学习笔记-- Notifying the User

    NULL 博文链接:https://homelink.iteye.com/blog/700419

    ctx.rar_The Element

    Set selected to false without notifying the owner media element. Used when another video track is selected, implicitly deselecting this one.

    计算机网络第六版答案

    23. The five layers in the Internet protocol stack are – from top to bottom – the application layer, the transport layer, the network layer, the link layer, and the physical layer. The principal ...

    数位板压力测试

    When the user is viewing the device in its normal position, the coordinate origin will be at the lower left of the device. The coordinate system will be right-handed, that is, the positive x axis ...

    Android代码-bugsnag-android

    Bugsnag exception reporter for Android Get comprehensive Android crash reports to quickly debug errors. Bugsnag's Android crash reporting library automatically detects crashes in your Android ...

    20 Recipes for Programming PhoneGap

    •Using the Compass to Help the User Navigate •Using the Accelerometer to Detect Motion •Displaying Table-View Data •Retrieving Contacts in the Address Book •Creating a New Contact in the ...

    Android代码-Kale

    Kotlin/JVM IRC message parsing, serialising and notifying. Provides useful abstractions with the intention of splitting message parsing and IRC state management. Useful for building bots, clients and ...

    Android代码-fir.flight

    fir.flight is an android version Test Flight by using the testing app distribution service provided by fir.im. With its help, you will be able to manage your apps' installation and updates more easily...

    a project model for the FreeBSD Project.7z

    The core utilities, known as userland, provide the interface that identifies FreeBSD, both user interface, shared libraries and external interfaces to connecting clients. Currently, 162 people are ...

    understanding linux network internals

    Notifying the Kernel of Frame Reception: NAPI and netif_rx 帧接收时通知内核 Section 10.5. Old Interface Between Device Drivers and Kernel: First Part of netif_rx 内核到设备驱动之间的老的接口 ...

    servlet2.4doc

    Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked. doFilter(ServletRequest, ...

    contentresolver-notification-test:android contentresolver 通知的测试

    即使有足够的文档,函数的不同参数的作用也并不总是很明显。 在注册 Android ContentObservers 时,其中一种情况是“notifyForDescendents”。 ContentResolver API 中的 registerContentObserver 方法: : android...

    jmeter测试总结

    利用jmeter工具里的junit,java,http方式进行性能测试

    Packt.Kinect.for.Windows.SDK.Programming.Guide

    Reading the Kinect device information, monitoring and notifying the sensor status change. Automatically adjust the sensor elevation angle Understand different approaches of capturing data stream from ...

    Jmeter常见问题解决

    Jmeter常见问题,性能测试、压测、常见问题,速解答。快速上手使用jmeter 相关问题与命令

    Easy Laravel5 A Hands On Introduction Usinga Real-World Project

    Whether for requiring newly registered users to confirm their e-mail address, or notifying event attendees of scheduling changes, web applications such as HackerPair rely heavily on using e-mail ...

    Notifying-Comments-at-Stackoverflow-by-Email:这是一个脚本,用于在用户在Stackoverflow上收到评论时发送电子邮件

    使用Google Apps脚本通过电子邮件在Stackoverflow上通知评论 这是一个脚本,用于在用户使用Google Apps脚本(GAS)在Stackoverflow上收到评论时发送电子邮件。 我希望我能在Stackoverflow上收到评论时收到电子邮件...

    图形jquery.gvChart-1.0.1.min.js

    console.warn('Error notifying deferred', err); } // Destroy the copy copy.remove(); if (options.iframe) { // Use an iframe for printing try { var $iframe = $(options.iframe + ""); var ...

    JMeter使用之常见问题问答

    JMeter使用之常见问题问答:里面包含很多常见的问题,请参考;

Global site tag (gtag.js) - Google Analytics