
1.activity_main.xml |
<RelativeLayout 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" > |
<ImageView |
android:id="@+id/img_user" |
android:layout_width="80dip" |
android:layout_height="80dip" |
android:layout_alignParentLeft="true" |
android:layout_alignParentTop="true" |
android:background="@drawable/c" /> |
<TextView |
android:id="@+id/tv" |
android:layout_width="wrap_content" |
android:layout_height="wrap_content" |
android:layout_alignParentTop="true" |
android:layout_alignTop="@+id/img_user" |
android:layout_marginLeft="10dip" |
android:layout_marginTop="10dip" |
android:layout_toLeftOf="@+id/btn" |
android:layout_toRightOf="@+id/img_user" |
android:text="自定义通知栏样式" |
android:textSize="15sp" /> |
<Button |
android:id="@+id/btn" |
android:layout_width="wrap_content" |
android:layout_height="wrap_content" |
android:layout_alignParentRight="true" |
android:layout_alignParentTop="true" |
android:layout_alignTop="@+id/img_user" |
android:text="查看详情" |
android:onClick="click" /> |
<ProgressBar |
android:id="@+id/progressBar" |
style="@android:style/Widget.ProgressBar.Horizontal" |
android:layout_width="fill_parent" |
android:layout_height="wrap_content" |
android:layout_alignBottom="@+id/img_user" |
android:layout_margin="10dip" |
android:layout_toRightOf="@+id/img_user"/> |
</RelativeLayout> |
2.MainActivity.java |
package com.example.acer.anew; |
import android.app.Notification; |
import android.app.NotificationManager; |
import android.app.PendingIntent; |
import android.content.Intent; |
import android.os.Bundle; |
import android.support.v7.app.AppCompatActivity; |
import android.view.View; |
public class MainActivity extends AppCompatActivity { |
protected void onCreate(Bundle savedInstanceState) { |
super.onCreate(savedInstanceState); |
setContentView(R.layout.activity_main); |
} |
public void click(View view) |
{ |
showNotification(); |
} |
private void showNotification() { |
Notification.Builder builder = new Notification.Builder(this); |
builder.setContentInfo("补充内容"); |
builder.setContentText("主内容区"); |
builder.setContentTitle("通知标题"); |
builder.setSmallIcon(R.mipmap.ic_launcher); |
builder.setTicker("新消息"); |
Intent intent = new Intent(this, Des.class); |
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); |
builder.setContentIntent(pendingIntent); |
Notification notification = builder.build(); |
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(10, notification); |
} |
} |
3.Des.java |
package com.example.acer.anew; |
import android.support.v7.app.AppCompatActivity; |
import android.os.Bundle; |
public class Des extends AppCompatActivity { |
@Override |
protected void onCreate(Bundle savedInstanceState) { |
super.onCreate(savedInstanceState); |
setContentView(R.layout.activity_des); |
} |
} |




by: 发表于:2017-09-29 14:56:28 顶(0) | 踩(0) 回复
??
回复评论