2010-06-22 67 views
4

我想知道如何在用戶單擊狀態欄中的通知時禁用突出顯示效果,此外,我想允許用戶直接進行交互與RemoteView我已通過按鈕按下通知。在狀態欄(Android)中實現交互式通知

我知道這可以做到,因爲HTC的Sense在完成上述目標的過程中正在進行通話。

請讓我知道如果您有任何想法,具體來說,我該如何設置嵌套在我的RemoteView中的視圖的OnClickListener?

回答

2

我還沒有嘗試過這個,但它應該像小部件使用RemoteViews.setOnClickPendingIntent一樣工作。禁用行選擇高亮顯示的一種方法可能是將點擊Intent添加到外部佈局元素,然後不對其執行任何操作。

例如,如果您的自定義佈局看起來像這樣。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/layout_root" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    <ImageView android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:src="@drawable/button"/> 
    <TextView android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Some Text" /> 
</LinearLayout> 

添加do_nothing意圖的layout_root,

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.yourlayout); 
notification.contentView = contentView; 

PendingIntent peClick = PendingIntent.getBroadcast(this, 0, new Intent("com.BUTTON_CLICK"), 0); 
contentView.setOnClickPendingIntent(R.id.button, peClick); 
PendingIntent peNothing = PendingIntent.getBroadcast(this, 0, new Intent("com.DO_NOTHING"), 0); 
contentView.setOnClickPendingIntent(R.id.layout_root, peNothing); 

BTW,HTC有權修改的Android的方式使用自己的東西的能力,正常的開發人員可以沒有,所以它並不總是好作爲可能的例子。

0

我仍然在做一些類似的代碼工作,但我迄今爲止的觀察是不同版本的Android處理事情的方式不同。在冰淇淋三明治上,使用setOnClickPendingIntent對佈局作品中的各個項目進行調整。但是,在Android的早期版本中,通知的contentIntent首先觸發,而按鈕的意圖不會觸發。這可能有一些解決辦法,但我還沒有找到它。爲通知的內容提供無所作爲的意圖似乎沒有幫助,因爲它仍然抓住了點擊。

+0

fyi- HoneyComb設置鴻溝。從HoneyComb開始,他們的工作。 – Falcon 2012-07-19 20:18:53