2014-05-23 34 views
1

PHP/C#/ ASP編碼器開始後,在Xamarin一槍(然後有一個6個月的間隙從所有編碼)Android適當地開始。自定義通知崩潰時使用setContent

我試圖實現通知內的自定義佈局。我可以讓它產生正常的通知,但當使用setContent(view)完成時,它不禁會崩潰。

也是Eclipse/ADT的新手,因此很難知道如何自己解決問題(在Visual Studio中很容易)。

爲了澄清,displayNotification當前設置爲在應用程序啓動時執行。

我確定它是如此簡單和小巧的事情,但是它已經越來越晚了,我的思緒也被打亂了。所有幫助非常感謝!

這是我的代碼(刪除了任何註釋掉的代碼只是爲了清理它)。

protected void displayNotification() { 

RemoteViews customNotificationView = 
new RemoteViews(getPackageName(), R.layout.notification_layout); 

NotificationCompat.Builder mBuilder = 
new NotificationCompat.Builder(this); 

mBuilder.setContent(customNotificationView); 
mBuilder.setTicker("New Message Alert!"); 
mBuilder.setSmallIcon(R.drawable.ic_launcher); 

mBuilder.setOngoing(true); 

mNotificationManager = (NotificationManager) 
getSystemService(Context.NOTIFICATION_SERVICE); 

mNotificationManager.notify(notificationID, mBuilder.build()); 
} 

這裏是我的自定義佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/notification_title" 
    style="@style/NotificationTitle" 
    /> 


<SeekBar 
    android:id="@+id/seekBar1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

回答

2

我測試你的代碼,它似乎沒有在佈局搜索欄工作正常。基於此answer,您無法在通知佈局上添加搜索欄。 我會看起來更好,後面評論。

編輯: 您可以嘗試將搜索欄更改爲按鈕並將onClick監聽器添加到它們,這裏是一個起點。 Adding onClick Action To Button In Notification

+1

謝謝!我可以看一下我的電腦。我從來沒有考慮過更改xml來測試(真的有點傻...但我學會了)。從我讀過的內容來看,它應該是可能的,但似乎它比我預期的要複雜。無論哪種方式都是一個好的起點。謝謝。 –

+1

正如你所說 - 刪除seekbar,然後它的作品。 我花了一些時間環顧四周,它似乎是一個磚牆,當涉及到一個seekbar ...但我沒有注意到一個應用程序在通知中複製seekbar。 [鏈接](https://play.google.com/store/apps/details?id=com.mortisapps.trayvolume)。 玩了這個,你不能滑動,但你可以按不同的位置 - 所以我想這是一個使用按鈕,並以某種方式樣式看起來像一個seekbar的情況。 這可能是我現在的方向。 –

+0

我也看過一些應用程序,並注意到同樣的事情,但我認爲這不是一件容易的事情。你可以做的是做兩個按鈕「上」和「下」,並顯示進度的百分比。你可以標記爲正確的答案? – dinhokz