2016-02-13 21 views
8

我的應用程序有一個我可以做成黑色或白色的標誌。我指定的啓動器圖標是黑色的,我想保留它的顏色。不過,我的應用程序使用的是黑色主題,最近的應用程序堆棧中應用程序標題欄的顏色也是黑色。黑色標題欄上的黑色圖標看起來很醜,特別是在白色文本旁邊。下面是一個截圖,以幫助解釋:Ugly color combination我可以爲android任務切換器設置不同的圖標嗎?

是否可以爲啓動器和任務切換器指定不同的圖標?

編輯:我看到Chrome做到了這一點:它將任務切換器圖標更改爲當前網站的圖標,因此除非該API是私有的,否則我完全知道這是可能的。

回答

1

是的,從API 21轉發開始,我們可以使用TaskDescription API在「最近的應用程序」屏幕中自定義應用程序的表示。

如果你只關心這個圖標,你可以使用下面從內Activity任意地點這個片段:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      setTaskDescription(
       new ActivityManager.TaskDescription(
        null, // Leave the default title. 
        R.drawable.the_icon_you_want, 
        null // Leave the default color      
     ) 
     } 

但是,你要記住,你的應用程序的最近的應用程式屏幕上呈現爲由您設置的最後一個TaskDescription確定。

由於從大書呆子牧場的真棒文章援引對此事:

By default, the TaskDescription is based on the activity at the base of the task’s activity stack. Other activities that pile on will not affect the styling, unless those activities have a TaskDescription explicitly set at run time. The topmost activity with a TaskDescription explicitly set will trump the styling specified in the manifest or in activities below in the stack with TaskDescriptions set.

因此達到最好的結果,你會想要把你的應用程序的MainActivityonCreate(..)方法內的片段。

+1

這給了我'錯誤:不兼容的類型:int不能轉換爲位圖,R.drawable.the_icon_you_want' – BeniBela

相關問題