我正在使用支持库v21中的新工具栏更新我的应用程序.我的问题是,如果我没有设置"高程"属性,工具栏不会投射任何阴影.这是正常行为还是我做错了什么?
我的代码是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
.
.
.
Run Code Online (Sandbox Code Playgroud)
在我的Activity - OnCreate方法中:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud) android material-design android-5.0-lollipop android-toolbar
我正在尝试"android: elevation ="在我的应用程序中使用,但一旦我运行它没有出现在Android 4.1.2的设备中
gradle这个
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.alvaro.proyectocaronte"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
Run Code Online (Sandbox Code Playgroud)
layout.xml
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="fill_parent"
android:background="@drawable/rounded_corner"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="93dp"
android:layout_marginEnd="93dp"
android:elevation="3dp"/>
Run Code Online (Sandbox Code Playgroud)
也许我没有为棒棒糖前装置正确编制Lollipop,有什么建议吗?
如果您需要查看代码的其他部分,我将编辑问题
谢谢
我在一个collapsingtoolbarlayout中设置了我的工具栏,如下所示:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试设置标题和副标题时,工具栏中只显示标题!
private void setupToolbar(){
toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
if(toolbar != null){
setSupportActionBar(toolbar);
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(mTitle);
getSupportActionBar().setSubtitle("Subtitle);
}
Run Code Online (Sandbox Code Playgroud)
如何访问工具栏的副标题?
在Appcompat v24.0.0中,在Activity可见之后导致阴影/高程渲染AppbarLayout.在阴影绘图中可以很容易地看到滞后AppbarLayout.
以前的Appcompat库版本中没有这种延迟.
使用Appcompat v24.0.0和Appcompat v23.4.0进行测试,在新版本中清晰显示阴影图.
我想在Lickipop设备上看到的KitKat设备上我的工具栏上显示相同的高程效果.以下是KitKat和Lollipop设备的屏幕截图.我已经提到了这个链接,但我的问题还没有解决.
棒棒糖装置:
Kitkat设备:
ContentMain.xml
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.global.market.checkinternet.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:background="#3F51B5"
style="@style/MyCustomTabLayout"
app:tabTextColor="#ffffff"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
app_bar_main.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
tools:context="com.global.market.MainActivity">
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) 经典的协调器布局为您提供以下[来源]:

但是,我不希望顶部标题视图滚动,直到它们“成为”固定在顶部的工具栏,下方有阴影。我希望它们全部固定(或固定),但要显示阴影,只有嵌套滚动视图开始在固定视图下滚动。类似于 Marshmallow 设备上的主应用程序抽屉,其中“搜索栏”被固定并且应用程序列表在其下方滚动。
希望我说清楚了。有没有什么简单的方法可以实现,而无需监听滚动事件并手动处理?
编辑
这是我想要实现的目标:
. 请注意右图,因为用户滚动了列表,所以现在在应用列表下方有一个阴影。
谢谢!
嗨,我正在尝试使用以下代码将阴影应用于线性布局
if (<some condition>)
layout.setElevation(4);
但是此调用需要API级别21才能工作.如何将阴影应用于版本<5.0的设备的布局?可能吗?
我知道这是材料设计的一部分,这就是为什么我只想知道是否有办法在以前的版本中实现类似的东西,谢谢:)