【发布时间】:2016-06-27 14:54:33
【问题描述】:
在 android 中,我有一个主要的浅色和状态栏,我可以在 #F3A183 和 #EC6F66 之间制作渐变吗?如果是这样,我该如何实现?
【问题讨论】:
标签: android android-layout material-design
在 android 中,我有一个主要的浅色和状态栏,我可以在 #F3A183 和 #EC6F66 之间制作渐变吗?如果是这样,我该如何实现?
【问题讨论】:
标签: android android-layout material-design
<android.support.v7.widget.Toolbar
android:id="@id/toolbar"
app:theme="@style/my_toolbar"
android:background="@drawable/ab_gradient"
android:elevation="5dp"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
ab_gradient.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="linear"
android:startColor="#F3A183"
android:endColor="#EC6F66"
android:angle="270"/>
</shape>
【讨论】:
你可以像这样设置工具栏的背景
toolbar.setBackgroundResource(R.drawable.gradient_one);
您的渐变可能如下所示
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners android:radius="9dp"/>
<gradient
android:startColor="#cc4151"
android:centerColor="#d95a5e"
android:endColor="#e27e70">
</gradient>
</shape>
【讨论】:
您还可以通过 ActionBar 以编程方式设置渐变颜色
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(AppCompatResources.getDrawable(context, R.drawable.toolbar_background));
toolbar_background 可绘制渐变颜色如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle:="45"
android:startColor="#F3A183"
android:endColor="#EC6F66">
</gradient>
<size android:width="24dp"/>
<size android:height="24dp"/>
</shape>
【讨论】: