1

我想在 android 状态栏中显示一些信息。但我不希望在通知中显示任何内容。但是当我向下拖动状态栏并看到通知栏时,我看到一个空白的通知位置。如果有人碰巧知道我怎样才能摆脱在通知栏中显示这个空白的通知位置?

我已阅读此链接http://developer.android.com/reference/android/app/Notification.html并尝试创建宽度和高度为零且没有通知图像和文本的自定义通知布局。但这没有帮助。我仍然在通知栏中看到通知的空白区域。

这是自定义通知布局

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:padding="0dp" >
</RelativeLayout>

这是我的代码膨胀通知

public class BatteryStatusBarActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final int HELLO_ID = 1;

    //Get a reference to the NotificationManager:
     String ns = Context.NOTIFICATION_SERVICE;
     NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);

    //Instantiate the Notification:
    int icon = R.drawable.notification_icon;
    CharSequence tickerText = "Hello";
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);

    //Define the notification's message and PendingIntent:
    Context context = getApplicationContext();
    Intent notificationIntent = new Intent(this, BatteryStatusBarActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, tickerText, tickerText, contentIntent);
    // redefine content view for notification
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
    notification.contentView = contentView;

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(HELLO_ID, notification);

    //mNotificationManager.cancel(HELLO_ID);    
}
}
4

0 回答 0