لطفا دوستان اگر مشکلی دیدن اصلاح کنن
بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ
رنگی کردن بک گراند نوتیفیکیشن
مدیریت گفتگو
آخرین تغییر: 11 سال پیش
سلام به همه دوستان.
میخواستم بدونم چه جوری بک گراند نوتیفیکیشنم رو رنگی و همچنین رنگ متنش رو هم عوض کنم.
اگه لطف کنید جواب بدید ممنون میشم.
پاسخها 3
<?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);
موفق باشید
نظرات
در پوشه 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>
نظرات
دیگه خودتون نسبت به علاقه تنظیماتو تغییر بدین
امیر جان این کد من برای ارسال نوتیفیکیشن 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)
نظرات
سهیل جان اون کد هم مثل اینا نوتیفیکشن میسازه
برای همه api ها؟
پس کلا برای نوتیفیکیشن ساختن از اون کد استفاده کنم حله؟
بزار تست کنم جوابش رو میگم
آره میتونی, فقط تغییراتو خودت اعمال کن دیگه, من 1 بار اینو نوشتم کار کرد حالا دیگه شما هرطور تصمیم میگیرید موفق باشین
تستش میکنم.نتیجه رو میگم
واقعا متشکرم امیر.مرسی.تا اینجا ک عالی بوده.ممنون
سایز عکسی که برای این نوتیفیکیشن میزاریم باید چند باشه؟سایز این: android:id="@+id/notifiation_image"
خواهش میکنم آقا, والا من 96x96 گذاشتم ولی فکر کنم بزرگترم بشه گذاشت, تو تنظیمات layout که ساختی براش تغییر بده ببین عمل میکنه, البته سرچم میشه کرد دیگه
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
ویرایش
پیام
نظرات