Java 透明渐变工具栏
我试图使工具栏渐变透明,但没有任何工作。这是我的密码 activity_main.xml(已更新)Java 透明渐变工具栏,java,android,toolbar,gradient,transparent,Java,Android,Toolbar,Gradient,Transparent,我试图使工具栏渐变透明,但没有任何工作。这是我的密码 activity_main.xml(已更新) 但我明白了: 如果有人知道怎么做,请帮助我 更新 AndroidManifest.xml <activity android:name=".activity.MainActivity" android:theme="@style/AppTheme.Transparent.NoActionBar" /> style.xml @android:color/tra
但我明白了:
如果有人知道怎么做,请帮助我
更新
AndroidManifest.xml
<activity
android:name=".activity.MainActivity"
android:theme="@style/AppTheme.Transparent.NoActionBar" />
style.xml
@android:color/transparent
@颜色/原色暗
@颜色/颜色重音
@颜色/浅灰色\u 1
@颜色/橙色1
@颜色/浅灰色\u 2
您需要将开始
和结束
颜色更改为透明
<gradient
android:angle="270"
android:startColor="@android:color/transparent"
android:endColor="@android:color/transparent"
android:type="linear" />
</shape>
直接使用@android:color/transparent
。跟随这一条-
工具栏布局-
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/background_toolbar_transparent" />
基本上作为堆栈工作,最后添加的项位于顶部
祝你好运
Emre仅将背景渐变应用于AppBarLayout
,并保留工具栏背景。为什么不直接在工具栏中设置透明颜色,而不是创建渐变背景?它已经是透明的,但缺少一些主题行为。发送您的清单和样式。xml@Bhavnik因为我不想要完全透明的工具栏。请参见预期图像。@EmreAktürk已在帖子中添加。不需要任何渐变背景吗?只是需要透明度??所以,只需在工具栏上使用android:background=“@android:color/transparent”
,而不是android:background=“@drawable/background\u toolbar\u transparent”
。如果你的代码正常工作,我只是错误地应用了它。谢谢;)你是说我应该删除AppBarLayout?是的,除非有理由保留它,否则用我的内容替换整个内容
<item name="colorPrimary">@android:color/transparent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorControlNormal">@color/light_grey_1</item>
<item name="colorControlActivated">@color/orange_1</item>
<item name="colorControlHighlight">@color/light_grey_2</item>
</style>
<gradient
android:angle="270"
android:startColor="@android:color/transparent"
android:endColor="@android:color/transparent"
android:type="linear" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/background_toolbar_transparent" />
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="270"
android:endColor="@android:color/transparent"
android:startColor="@color/black_alpha"/>
</shape>
<color name="black_alpha">#66000000</color>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark"
android:orientation="vertical">
<!-- Your content comes here -->
<android.support.v7.widget.Toolbar
android:id="@+id/layout_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:elevation="6dp"
tools:targetApi="lollipop"/>
</FrameLayout>