-2
Q
彩虹效果
A
回答
0
public static TextView getToolbarTitleView(ActionBarActivity activity, Toolbar toolbar){
ActionBar actionBar = activity.getSupportActionBar();
CharSequence actionbarTitle = null;
if(actionBar != null)
actionbarTitle = actionBar.getTitle();
actionbarTitle = TextUtils.isEmpty(actionbarTitle) ? toolbar.getTitle() : actionbarTitle;
if(TextUtils.isEmpty(actionbarTitle)) return null;
// can't find if title not set
for(int i= 0; i < toolbar.getChildCount(); i++){
View v = toolbar.getChildAt(i);
if(v != null && v instanceof TextView){
TextView t = (TextView) v;
CharSequence title = t.getText();
if(!TextUtils.isEmpty(title) && actionbarTitle.equals(title) && t.getId() == View.NO_ID){
//Toolbar does not assign id to views with layout params SYSTEM, hence getId() == View.NO_ID
//in same manner subtitle TextView can be obtained.
return t;
}
}
}
return null;
}
TextView tv= getToolBarTitleView(activity,toolbar);
if(tv!=null){
Shader textShader=new LinearGradient(0, 0, 0, 20,
new int[]{Color.YOURCOLOR,Color.YOURCOLOR},
new float[]{0, 1}, TileMode.CLAMP);
tv.getPaint().setShader(textShader);
}
else{
Log.e("MYPROJECT","No textview in toolbar . . . ");
}
+0
thx,我用你的getToolbarTitleView()結合第一條評論的github鏈接,它的工作:) –
+0
高興地幫助你:) –
相關問題
- 1. 彩虹效應多用戶
- 2. java畫彩虹
- 3. 開發彩虹表
- 4. 彩虹的接近度
- 5. openGL中的彩虹線es
- 6. 創建(彩虹)調色板
- 7. 彩虹表和加密
- 8. 給我一個彩虹
- 9. 翹曲R中的彩虹
- 10. 從freerainbowtables.com讀取彩虹桌
- 11. 彩虹色的傳說R
- 12. Java Swing:JComponent的彩虹邊框
- 13. 顯示色彩效果
- 14. 更改彩虹蟲的顏色
- 15. 如何在Freeglut中繪製彩虹?
- 16. 彩虹jQuery插件不起作用
- 17. pygame上不需要的彩虹圖標
- 18. SHA256彩虹桌減少算法
- 19. rgb2gray不工作,創造彩虹圖像
- 20. Groovy排序顏色的彩虹
- 21. 彩虹表:如何防禦他們?
- 22. 創建漸變/彩虹strokeStyle html5 canvas
- 23. 存儲在Django和彩虹表密碼
- 24. 彩虹表 - 散列減少 - Java
- 25. Java生成彩虹色 - 如何?
- 26. 如何渲染彩虹光譜?
- 27. 維基百科彩虹表項
- 28. 將彩虹色映射到RGB
- 29. 爲什麼鹽會阻止彩虹桌?
- 30. C#無限彩虹背景循環
可以使用貼在這裏的建議https://chiuki.github.io/advanced-android-textview/#/ 38創建自定義的RainbowSpan,然後使用SpannableString作爲標題。 –
thx,我用你的意見與Arsen Sench的答案組合,它的工作原理 –