【发布时间】:2011-09-01 05:22:34
【问题描述】:
那里有很多关于实现自定义标题栏的教程和问题。但是,在我的自定义标题栏中,我有一个自定义背景渐变,我想知道如何在我的代码中动态设置它。
这里是我的自定义标题栏被调用的地方:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.foo_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
这是我的custom_title_bar:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/custom_title_bar_background_colors">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/title_bar_logo"
android:gravity="center_horizontal"
android:paddingTop="0dip"/>
</LinearLayout>
如你所见,线性布局上的背景是由这个人定义的:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#616261"
android:endColor="#131313"
android:angle="270"
/>
<corners android:radius="0dp" />
</shape>
我想做的是在我的代码中动态设置这些渐变颜色。我不想像现在这样在我的 XML 文件中硬编码它们。
如果您有更好的方法来设置背景渐变,我愿意接受所有想法。
提前谢谢你!!
【问题讨论】:
标签: android android-layout background gradient