بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ

رنگی کردن بک گراند نوتیفیکیشن

مدیریت گفتگو
سهیل 11 سال پیش
آخرین تغییر: 11 سال پیش

سلام به همه دوستان.

میخواستم بدونم چه جوری بک گراند نوتیفیکیشنم رو رنگی و همچنین رنگ متنش رو هم عوض کنم.

اگه لطف کنید جواب بدید ممنون میشم.

نظرات

سهیل 11 سال پیش
از دوستان کسی بلد نیست؟من زیاد از این نوع نوتیفیکیشن دیدم
سهیل 11 سال پیش
واقعا هیچکی بلد نیست؟
Amir.z 11 سال پیش
در زمان ساخت لایه برای نوتیفیکیشن از لایه Relative استفاده کنید و یک imageView با عکس دلخواه
سهیل 11 سال پیش
در زمان ساخت کجا بهش یه لایه Relative معرفی کنم؟من برای نشان دادن نوتیفیکیشن از دو کلاس Notification.Builder و Notification برای api های مختلف استفاده میکنم.
سهیل 11 سال پیش
اگر کسی راه حلی بده متشکر میشم.

پاسخ‌ها 3

Amir.z 11 سال پیش

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="space_name"
    android:id="@+id/custom_notification"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

    <ImageView
        android:id="@+id/notifiation_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/notification_title"
        style="@style/NotificationTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/notification_image"
        android:layout_toRightOf="@id/notification_image" />

    <TextView
        android:id="@+id/notification_text"
        style="@style/NotificationText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/notification_title"
        android:layout_toRightOf="@+id/notification_image" />

</RelativeLayout>
  int NOTIFICATION_ID = 1;
        int icon = R.drawable.ic_add;
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, "Hello", when); //getString(R.string.text)

        RemoteViews contentView = new RemoteViews("your_pakage_name", R.layout.custom_notification);
        contentView.setImageViewResource(R.id.notification_image, R.drawable.ic_logo);
        contentView.setTextViewText(R.id.notification_title, "My custom notification title");
        contentView.setTextViewText(R.id.notification_text, "My custom notification text");
        notification.contentView = contentView;

        Intent notificationIntent = new Intent(this, yourSctivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(G.context, 0, notificationIntent, 0);
        notification.contentIntent = contentIntent;

        //notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
        notification.defaults |= Notification.FLAG_AUTO_CANCEL;//canclable with click
        notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
        notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
        notification.defaults |= Notification.DEFAULT_SOUND; // Sound

        G.mNotificationManager.notify(NOTIFICATION_ID, notification);

موفق باشید

نظرات

Amir.z 11 سال پیش
لطفا دوستان اگر مشکلی دیدن اصلاح کنن
سهیل 11 سال پیش
واقعا متشکرم امیر.دمت گرم.تستش میکنم و نتیجش رو میگم.
سهیل 11 سال پیش
این خط ارور داره style="@style/NotificationText"
Amir.z 11 سال پیش

در پوشه value  یک فایل style بسازید

 <?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="NotificationText">
        <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
    </style>

    <style name="NotificationTitle">
        <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
        <item name="android:textStyle">bold</item>
    </style>

</resources>

نظرات

Amir.z 11 سال پیش
دیگه خودتون نسبت به علاقه تنظیماتو تغییر بدین
سهیل 11 سال پیش

امیر جان این کد من برای ارسال نوتیفیکیشن api بالای 11:

              Intent intent1 = new Intent(context, khabarNotVojodView.class);   
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent1, PendingIntent.FLAG_ONE_SHOT); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder mBuilder = new Notification.Builder(context) .setSmallIcon(R.drawable.iconkochik) .setContentIntent(pendingIntent) .setTicker(KHnotification_description_khabarNotVojod) .setLargeIcon(myBitmap) .setContentText(KHName_khabarNotVojod) .setContentTitle(KHnotification_description_khabarNotVojod) .setAutoCancel(true); Notification notif = mBuilder.getNotification(); nm.notify(321, notif);

و این هم برای زیر 11 هست:

             Intent intent1 = new Intent(context, khabarNotVojodView.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent1, PendingIntent.FLAG_ONE_SHOT); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notif = new Notification( R.drawable.iconkochik, KHnotification_description_khabarNotVojod, System.currentTimeMillis()); CharSequence from = KHnotification_description_khabarNotVojod; // CharSequence from = "پنح"; CharSequence message = KHName_khabarNotVojod; // CharSequence message = "برنامه ای بسیار جذاب"; notif.setLatestEventInfo(context, from, message, pendingIntent); nm.notify(321, notif);

اون کدی که دادی باید کجا وارد بشه؟(Remote Views)

نظرات

Amir.z 11 سال پیش
سهیل جان اون کد هم مثل اینا نوتیفیکشن میسازه
سهیل 11 سال پیش
برای همه api ها؟
سهیل 11 سال پیش
پس کلا برای نوتیفیکیشن ساختن از اون کد استفاده کنم حله؟
سهیل 11 سال پیش
بزار تست کنم جوابش رو میگم
Amir.z 11 سال پیش
آره میتونی, فقط تغییراتو خودت اعمال کن دیگه, من 1 بار اینو نوشتم کار کرد حالا دیگه شما هرطور تصمیم میگیرید موفق باشین
سهیل 11 سال پیش
تستش میکنم.نتیجه رو میگم
سهیل 11 سال پیش
واقعا متشکرم امیر.مرسی.تا اینجا ک عالی بوده.ممنون
سهیل 11 سال پیش
سایز عکسی که برای این نوتیفیکیشن میزاریم باید چند باشه؟سایز این: android:id="@+id/notifiation_image"
Amir.z 11 سال پیش
خواهش میکنم آقا, والا من 96x96 گذاشتم ولی فکر کنم بزرگترم بشه گذاشت, تو تنظیمات layout که ساختی براش تغییر بده ببین عمل میکنه, البته سرچم میشه کرد دیگه

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .