Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. import android.app.Notification;
  2. import android.app.NotificationManager;
  3. import android.os.Bundle;
  4. import android.support.v4.app.NotificationCompat;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.support.v7.widget.Toolbar;
  7.  
  8. public class MainActivity extends AppCompatActivity
  9. {
  10. private final int NOTIFICATION_ID = 10;
  11.  
  12. @Override
  13. protected void onCreate (Bundle savedInstanceState)
  14. {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_main);
  17.  
  18. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  19. setSupportActionBar(toolbar);
  20.  
  21. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
  22. mBuilder.setContentTitle("Value");
  23. mBuilder.setContentText("123");
  24. mBuilder.setSmallIcon(R.mipmap.ic_launcher);
  25. mBuilder.setOngoing(true);
  26. mBuilder.setAutoCancel(false);
  27.  
  28. //Intent resultIntent = new Intent(this, MainActivity.class);
  29. //PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  30. //mBuilder.setContentIntent(resultPendingIntent);
  31.  
  32. Notification notification = mBuilder.build();
  33. notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
  34.  
  35. NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  36. mNotifyMgr.notify(NOTIFICATION_ID, notification);
  37. }
  38. }
  39.  
  40. <?xml version="1.0" encoding="utf-8"?>
  41. <RelativeLayout
  42. xmlns:android="http://schemas.android.com/apk/res/android"
  43. xmlns:app="http://schemas.android.com/apk/res-auto"
  44. xmlns:tools="http://schemas.android.com/tools"
  45. android:layout_width="match_parent"
  46. android:layout_height="match_parent"
  47. android:fitsSystemWindows="true"
  48. tools:context=".MainActivity">
  49.  
  50. <android.support.design.widget.CoordinatorLayout
  51. android:layout_width="match_parent"
  52. android:layout_height="match_parent">
  53.  
  54. <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
  55. android:layout_width="match_parent"
  56. android:theme="@style/AppTheme.AppBarOverlay">
  57.  
  58. <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
  59. android:layout_width="match_parent"
  60. android:layout_height="wrap_content"
  61. android:background="#000000"
  62. app:popupTheme="@style/AppTheme.PopupOverlay" />
  63.  
  64. </android.support.design.widget.AppBarLayout>
  65.  
  66. <LinearLayout
  67. android:layout_width="match_parent"
  68. android:layout_height="match_parent"
  69. android:layout_alignParentLeft="true"
  70. android:layout_alignParentTop="true"
  71. android:orientation="vertical"
  72. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  73. android:weightSum="100" >
  74.  
  75. <TextView
  76. android:id="@+id/tv_value"
  77. android:layout_width="wrap_content"
  78. android:layout_height="wrap_content"
  79. android:text="Hello World!"
  80. app:layout_constraintBottom_toBottomOf="parent"
  81. app:layout_constraintLeft_toLeftOf="parent"
  82. app:layout_constraintRight_toRightOf="parent"
  83. app:layout_constraintTop_toTopOf="parent"/>
  84.  
  85. </LinearLayout>
  86.  
  87. </android.support.design.widget.CoordinatorLayout>
  88.  
  89. </RelativeLayout>
  90.  
  91. https://i.stack.imgur.com/HP8ac.png
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement