Я использую RemoteViews
для создания пользовательского уведомления. Есть ли способ настроить область уведомлений специально по высоте...??? Я не хочу использовать BigView
, потому что мне нужно использовать его для API менее 11.
Санпшоты это:
Вот мой код:
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notificationmain);
Button bnotify = (Button) findViewById(R.id.notification);
Button bcustomnotify = (Button) findViewById(R.id.customnotification);
// Click For Default Notification
bnotify.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Notification();
}
});
// Click For Custom Notification
bcustomnotify.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
CustomNotification();
}
});
}
// Default Notification
public void Notification() {
String strtitle = getString(R.string.notificationtitle);
String strtext = getString(R.string.notificationtext);
Intent intent = new Intent(this, NotificationView.class);
intent.putExtra("title", strtitle);
intent.putExtra("text", strtext);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logosmall)
.setTicker(getString(R.string.notificationticker))
.setContentTitle(getString(R.string.notificationtitle))
.setContentText(getString(R.string.notificationtext))
.addAction(R.drawable.ic_launcher, "Action Button", pIntent)
.setContentIntent(pIntent)
.setAutoCancel(true);
// Create Notification Manager
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
}
// Custom Notification
public void CustomNotification() {
// Using RemoteViews to bind custom layouts into Notification
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.customnotification);
String strtitle = getString(R.string.customnotificationtitle);
String strtext = getString(R.string.customnotificationtext);
Intent intent = new Intent(this, NotificationView.class);
intent.putExtra("title", strtitle);
intent.putExtra("text", strtext);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logosmall)
.setTicker(getString(R.string.customnotificationticker))
.setAutoCancel(true)
.setContentIntent(pIntent)
.setContent(remoteViews);
remoteViews.setImageViewResource(R.id.imagenotileft,R.drawable.ic_launcher);
remoteViews.setImageViewResource(R.id.imagenotiright,R.drawable.androidhappy);
remoteViews.setTextViewText(R.id.title,getString(R.string.customnotificationtitle));
remoteViews.setTextViewText(R.id.text,getString(R.string.customnotificationtext));
Calendar cal = Calendar.getInstance();
cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
remoteViews.setTextViewText(R.id.time,sdf.format(cal.getTime()) );
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(1, builder.build());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
customnotification
и используя изображение меньшего размера. - person Joel Fernandes   schedule 19.06.201464 dp
, а макеты расширенного просмотра ограничены256 dp
. - person M D   schedule 19.06.2014customnotification
, но высота осталась прежней... - person BST Kaal   schedule 19.06.2014