adroid自定义notification通知栏

DmNotificationManager.Builder builder =
                        DmNotificationManager.getDefaultBuild(getApplicationContext(),
                                getResources().getText(R.string.feedback_notification_title),
                                getResources().getText(R.string.feedback_notification_title),
                                startIntent, FEED_BACK_SERVICE_NOTIFICATION_ID);
                RemoteViews conterViews =
                        new RemoteViews(getPackageName(), R.layout.feedback_layout);
                conterViews.setTextViewText(R.id.feed_back_tv,
                        getResources().getText(R.string.feedback_notification_title));
//                conterViews.setTextColor(R.id.feed_back_tv, Color.RED);
                builder.setContent(conterViews);
                builder.setAutoCancel(true);
                builder.setSmallIcon(R.drawable.icon21);
                builder.setWhen(System.currentTimeMillis());
                // builder.setNumber(0);
                builder.setTicker(getResources().getText(R.string.feedback_notification_title));
                builder.setEnableLight(true);
                builder.setEnableSound(true);
                builder.setEnableVibrate(true);

                DmNotificationManager.getInstance().showNotify(builder);

最主要的是RemoteViews,这个里面放的feedback_layout就是自定义的布局,可以手动设置里面内容,

通过conterViews.setTextViewText(R.id.feed_back_tv,getResources().getText(R.string.feedback_notification_title));方法。

builder.setTicker(getResources().getText(R.string.feedback_notification_title));是设置滚动的通知栏的内容

下面是layout代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="65sp"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="10dp"
        android:background="@drawable/icon"
        android:gravity="center_vertical" />

    <TextView
        android:id="@+id/feed_back_tv"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="20dp"
        android:gravity="center_vertical"
        android:textSize="17sp" />

</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值