-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. 彩虹表和加密
- 3. openGL中的彩虹线es
- 4. Java Swing:JComponent的彩虹边框
- 5. 创建(彩虹)调色板
- 6. 从freerainbowtables.com读取彩虹桌
- 7. 给我一个彩虹
- 8. 显示色彩效果
- 9. SHA256彩虹桌减少算法
- 10. 更改彩虹虫的颜色
- 11. C#无限彩虹背景循环
- 12. rgb2gray不工作,创造彩虹图像
- 13. pygame上不需要的彩虹图标
- 14. 存储在Django和彩虹表密码
- 15. 维基百科彩虹表项
- 16. 将彩虹色映射到RGB
- 17. 彩虹表:如何防御他们?
- 18. jQuery的动画彩虹般的色彩变化
- 19. PhpStorm - 搜索变化的色彩效果
- 20. BlitzMax - 为PNG文件生成2D霓虹灯发光线效果
- 21. 旧的彩色电影效果和炙手可热的海报效果
- 22. 是否有任何崇高的文字包装彩虹括号?
- 23. 连锁店如何在彩虹桌上工作?
- 24. 如何在C#中获得彩虹颜色渐变?
- 25. R:调色板(彩虹())没有为第一次尝试更新
- 26. Android中的彩虹式颜色选择器
- 27. 如何绘制渐变填充弧,即彩虹?
- 28. 彩虹表的密码长度是多少?
- 29. 用Python在文本文件中创建彩虹表
- 30. 呈现在Java中的OpenGL彩虹魔影并没有融入
可以使用贴在这里的建议https://chiuki.github.io/advanced-android-textview/#/ 38创建自定义的RainbowSpan,然后使用SpannableString作为标题。 –
thx,我用你的意见与Arsen Sench的答案组合,它的工作原理 –