Android Gradient Application Title Bar [duplicate]

主宰稳场 提交于 2019-12-20 06:13:57

问题


Possible Duplicate:
How do I programmatically set the background color gradient on a Custom Title Bar?

I want to use gradient color in application title bar. How can I do it?

Thanks in advance.


回答1:


All people are trying to use Custom title for this requirement.

I achieved this without using custom title. Just use below code in your activity's onCreate() after setContentView().

GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {Color.RED,Color.GREEN});
View title = getWindow().findViewById(android.R.id.title);
View titleBar = (View) title.getParent();
titleBar.setBackgroundDrawable(gd);

Enjoy with above code. Below image is screen shot of my app with gradient color as title bar background.



来源:https://stackoverflow.com/questions/9014944/android-gradient-application-title-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!