Android的梯度应用程序标题栏梯度、应用程序、标题栏、Android

2023-09-04 05:23:26 作者:以可爱出名

可能重复:   How我编程设置背景颜色渐变的自定义标题栏?

我想使用的应用程序标题栏的渐变色。我该怎么办呢?

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

在此先感谢。

推荐答案

所有的人都在试图用自定义标题作为这一要求。

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

我不使用自定义的标题来实现这一点。的setContentView后只需要用下面code。在您的活动的onCreate()()。

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);

享受以上code。下面的图片是屏幕截图我用渐变的颜色作为标题栏背景的应用程序的。

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