Android custom notification bar, android custom notification

Source: Internet
Author: User

Android custom notification bar, android custom notification

Package com. example. mvp;

Import cn. ljuns. temperature. view. TemperatureView;
Import presenter. ILoginPresenter;
Import presenter. LoginPresenterCompl;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. app. Notification;
Import android. app. icationicationmanager;
Import android. app. PendingIntent;
Import android. graphics. BitmapFactory;
Import android. graphics. Color;
Import android. graphics. drawable. BitmapDrawable;
Import android. util. Log;
Import android. view. Gravity;
Import android. view. LayoutInflater;
Import android. view. Menu;
Import android. view. VelocityTracker;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. view. Window;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. PopupWindow;
Import android. widget. RemoteViews;
Import android. widget. Toast;
Import android. app. ActionBar. LayoutParams;
Import android. content. Context;
Import android. content. Intent;
Public class MainActivity extends Activity implements ILoginView {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// RequestWindowFeature (Window. FEATURE_NO_TITLE );
SetContentView (R. layout. activity_main );
Notification notification = new Notification ();
// Set the icon. The custom Layout image will overwrite it, but you still have to set it. Otherwise, it will not be displayed in the notification bar.
Notification. icon = R. drawable. ic_launcher;
Notification. tickerText = "hello I am gougou ";
Notification. when = System. currentTimeMillis ();
Notification. flags = Notification. FLAG_AUTO_CANCEL;
// Enter the package name of the current project and the ID of the custom layout to be displayed in the notification bar
RemoteViews remoteViews = new RemoteViews (getPackageName (), R. layout. activity_amain );
// The following are the properties of the control in the notification bar layout.
RemoteViews. setImageViewResource (R. id. imageView1, R. drawable. hot );
RemoteViews. setTextColor (R. id. textView1, Color. RED );
RemoteViews. setTextViewText (R. id. textView1, "hello I am basket ");
RemoteViews. setTextViewTextSize (R. id. textView1, 1, 15 );
// PendingIntent has four types of flag.
//-FLAG_ONE_SHOT only once
//-FLAG_NO_CREATE: if the specified Intent does not exist, NULL is returned.
//-FLAG_CANCEL_CURRENT if the PendingIntent already exists, the current
//-FLAG_UPDATE_CURRENT is always executed, and this flag is used most
PendingIntent pendingIntent = PendingIntent. getActivity (
This, 0, new Intent (this, AMainActivity. class ),
PendingIntent. FLAG_UPDATE_CURRENT );
RemoteViews. setOnClickPendingIntent (R. id. textView1, pendingIntent );
Notification. contentView = remoteViews;
Notification. contentIntent = pendingIntent;

Icationicationmanager manager = (NotificationManager) getSystemService (Context. NOTIFICATION_SERVICE );
Manager. Y (1, notification );
}

R. layout. activity_amain layout

<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"
Tools: context = ". AMainActivity">


<ImageView
Android: id = "@ + id/imageView1"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
/>
<TextView
Android: id = "@ + id/textView1"
Android: layout_width = "0dp"
Android: layout_weight = "1"
Android: layout_height = "wrap_content"
Android: clickable = "true"
/>


<TextView
Android: id = "@ + id/textView2"
Android: layout_width = "0dp"
Android: layout_weight = "1"
Android: layout_height = "wrap_content"
/>
</LinearLayout>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.