Академический Документы
Профессиональный Документы
Культура Документы
Android
No)ca)on
UI
tools
Toasts
No)ca)ons
Manager
Dialog
box
Toasts
Transient
Non-modal
Dialog
box
User
to
display
informa)on
to
user
without
stealing
focus
from
the
ac)ve
applica)ons
Examples
Context
context
=
getApplica)onContext();
String
msg
=
To
health
and
happiness!
Int
dura)on
=
Toast.LENGTH_SHORT;
Toast
toast
=
Toast.makeText(context,
msg
,
dura)on);
Toast.show();
Result
No)ca)ons
More
robust
mechanism
for
aler)ng
users
Ring
tone
Vibra)on
Flashing
of
LED
Status
bar
icons
to
indicate
an
event
No)ca)on
Manager
System
Service
used
to
handle
no)ca)ons.
Get
reference
to
it
using
the
getSystemService
method
E.g.
String
svcName
=
Context.NOTIFICATION_SERVICE;
No)ca)onManager
no)ca)onManager;
no)ca)onManager=
(No)ca)onManager)getSystemService(svcName)
Or
No)ca)onManager
no)ca)onManager
=
(No)ca)onManager) getSystemService(CONTEXT.NOTIFICATION_SERVICE);
Example
BuZon
btnShowNo)ca)on;
No)ca)onManager
no)ca)onManager;
No)ca)on
no)ca)on;
int
no)ca)onRef;
Example
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
no)ca)onRef
=
1;
String
svcName
=
Context.NOTIFICATION_SERVICE;
int
icon
=
R.drawable.icon;
String
)ckerText
=
"No)ca)on";
long
when
=
System.currentTimeMillis();
Example
no)ca)on
=
new
No)ca)on(icon,)ckerText,
when);
Context
context
=
getApplica)onContext();
String
expandedText
=
"Extended
status
text";
String
expandedTitle
=
"No)ca)on
Title";
Intent
intent
=
new
Intent(this,myNo)ca)onManager.class);
PendingIntent
launchIntent
=
PendingIntent.getAc?vity(context,
0,
intent,
0);
no)ca)on.setLatestEventInfo(context,
expandedTitle,
expandedText,launchIntent);
Example
btnShowNo)ca)on
=
(BuZon)
ndViewById(R.id.btnShowNo?ca?on);
btnShowNo)ca)on
.setOnClickListener(new
OnClickListener()
{
public
void
onClick(View
v)
{
}
});
no)ca)onManager
.no)fy(no)ca)onRef,
no)ca)on);
Result
Result
Dialogs
Two
methods
of
doing
it
Changing
of
manifest
(Customized)
Using
of
default
Dialogs
Two
methods
of
doing
it
Changing
of
manifest
(Customized)
Using
of
default
DIY
Normal
Ac)vity
Change
of
theme
in
manifest
le
Informing
the
OS
to
treat
ac)vity
as
a
dialog
E.g.
<ac)vity
android:name=".myDialog"
android:theme="@android:style/Theme.Dialog
</ac)vity>
DIY : Result
Default
Dialogs
AZached
to
Ac)vity
Sequence
Call
showDialog(
int
id
);
Override
onCreateDialog(
int
id
)
method
Default
Dialogs
E.g.
public
void
onClick(View
v)
{
//
TODO
Auto-generated
method
stub
showDialog(0);
Default
Dialogs
E.g.
protected
Dialog
onCreateDialog(int
id)
{
Dialog
retDialog;
switch(id)
{
}
}
Default
Dialogs
E.g.
retDialog
=
new
AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle("Dialog
Text")
.setPosi)veBuZon("Ok",
new
DialogInterface.OnClickListener()
{
@Override
public
void
onClick(DialogInterface
dialog,
int
which)
{
}
})
.create();
Customized: Result