2017-06-16 135 views
0

我的目標是設置rtl支持推送通知。我的通知切換文本方向,但不是佈局的位置。例如圖標總是在左邊,標題在右邊而文字在左邊。我的猜測是所有的東西都應該放在左邊或右邊。我試圖創建自定義的XML,但問題是我無法在遠程視圖上設置layoutDirection。代碼中使用:Android設置rtl支持推送通知

標準通知:

mNotification = new NotificationCompat.Builder(context) 
    .setContentTitle(contentTitle) 
    .setContentText(contentText) 
    .setSmallIcon(appIcon) 
    .setContentIntent(contentIntent) 
    .setSound(soundUri) 
    .setAutoCancel(true) 
    .setWhen(started) 
    .build(); 

和自定義XML:

RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.my_id); 
       contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher); 
       contentView.setTextViewText(R.id.title, contentTitle); 
       contentView.setTextViewText(R.id.text, "Text ")); 

mNotification.contentView = contentView; 

回答

0

通知佈局由Android系統自動處理。如果圖標位於RTL模式的左側,這是有原因的,並且每個通知都會在設備上顯示。即使您設法更改應用通知的佈局,用戶也會對通知佈局不一致感到困惑。

您可以在Material Design Guidelines中瞭解有關通知佈局的更多信息。

+0

這不是一個答案。請刪除它 – TeodorKolev