-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的答案组合,它的工作原理 –