cac*_*zio 6 android android-layout android-toolbar
我正在尝试禁用透明AppBarLayout /工具栏下方的阴影.这是布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#000">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/imagePreviewToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_image_preview" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我已经试过了
app:elevation="0dp"
Run Code Online (Sandbox Code Playgroud)
和
getSupportActionBar().setElevation(0);
Run Code Online (Sandbox Code Playgroud)
但这使UP箭头不可见.我还尝试删除AppBarLayout并仅使用工具栏,但问题仍然存在.
有人有解决方案吗?
编辑:
用以下代码替换AppBarLayout + Toolbar组合:
<android.support.v7.widget.Toolbar
android:id="@+id/imagePreviewToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:elevation="0dp"/>
Run Code Online (Sandbox Code Playgroud)
部分修复了问题.现在,只有当设备处于横向模式时,工具栏才会变为不可见!Android Studio布局编辑器向我展示了两个方向的工具栏就好了,所以我真的不知道问题是什么.
Muh*_*der 15
经过一些尝试,我确实发现ToolBar应该是这种情况下的最后一个视图,否则如果它将是第一个,那么它之后的视图将重叠它,因为它已经设置了高度,match_parent所以在布局中尝试这种方式.
布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/imagePreviewToolbar" >
<ImageView
android:id="@+id/image_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/galacticos"
android:contentDescription="abc"
android:scaleType="fitCenter" />
<LinearLayout
android:id="@+id/actionBtns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:padding="16dp" >
<ImageButton
android:id="@+id/setBackgroundBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:contentDescription="abc"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/downloadBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="abc"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/imagePreviewToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
Run Code Online (Sandbox Code Playgroud)
并且不要忘记初始化所有并将标题设置为false以仅显示toolBar后退按钮:
活动代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Toolbar mToolBar = (Toolbar) findViewById(R.id.imagePreviewToolbar);
setSupportActionBar(mToolBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)
希望我能帮助你.
| 归档时间: |
|
| 查看次数: |
3329 次 |
| 最近记录: |