Android Gradient应用程序标题栏

Zah*_*bib 0 android titlebar

可能重复:
如何在自定义标题栏上以编程方式设置背景颜色渐变?

我想在应用程序标题栏中使用渐变颜色.我该怎么做?

提前致谢.

Yug*_*abu 6

所有人都试图使用自定义标题来满足此要求.

我没有使用自定义标题就达到了这个 只需在setContentView()之后在活动的onCreate()中使用下面的代码.

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);
Run Code Online (Sandbox Code Playgroud)

享受以上代码.下面的图像是我的应用程序的屏幕截图,渐变颜色作为标题栏背景.

作为标题栏背景的梯度颜色