我四处搜寻,找不到合适的方法.我想对我的观点产生以下阴影效果:


说实话,我不知道第二个是否通过应用阴影效果来完成.有任何想法吗?
谷歌已经表明,海拔效果显示在棒棒糖一些不错的方式在这里.
android:elevation="2dp"
Run Code Online (Sandbox Code Playgroud)
按钮,
android:stateListAnimator="@anim/button_state_list_animator"
Run Code Online (Sandbox Code Playgroud)
如何在没有第三方库的情况下模仿前Lollipop版本的高程效果?
我正在尝试"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,有什么建议吗?
如果您需要查看代码的其他部分,我将编辑问题
谢谢
这是一个简单的问题:
我使用新的支持库,它允许我拥有一个工具栏实例,甚至将其设置为活动的actionBar(或使用默认的).
如何自定义工具栏(或默认ActionBar)投射的阴影?
我试过使用"setElevation"(两者都有),但它似乎没有在Android Lollipop上做任何事情.
另外,我找不到如何在Lollipop前版本上自定义阴影.可能有这个API吗?或至少是一个drawable(我没有找到,即使我已经尝试过)?
好的,我已经设法找到了下一件事:
对于Lollipop和pre-Lollipop,当您的活动使用正常的AppCompat主题(例如"Theme.AppCompat.Light")时,阴影应该看起来很好.
但是,当您使用"setSupportActionBar"(并使用适当的主题,例如"Theme.AppCompat.Light.NoActionBar")时,您将遇到阴影的一些问题.
对于pre-Lollipop,你可以在工具栏下面放置一个FrameLayout,它看起来就像用于普通主题的那样,如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:foreground="?android:windowContentOverlay"
android:visibility="@integer/action_bar_shadow_background_visibility" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:text="@string/hello_world" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
您可以使用FrameLayout作为活动的内容,或使用我所做的.您还可以通过为棒棒糖前置整数0和为棒棒糖及以上版本放置2来设置其可见性,就像我使用"action_bar_shadow_background_visibility"一样.
这是一个丑陋的解决方案,但它可以工作,但仅限于前Lollipop版本.
在任何情况下,如果我使用"setSupportActionBar",我仍然无法找到一种方法来为Lollipop显示阴影.我尝试在工具栏和操作栏上使用"setElevation"(在调用"setSupportActionBar"之后立即使用"getSupportActionBar").
我也没有得到如何获得动作栏的标准高度,因为我注意到许多教程说使用"minHeight"作为工具栏.非常感谢这方面的帮助.
谁能帮我这个?
再说一次,为了说清楚,这就是我的要求:
编辑:好的,到目前为止,这是模仿Lollipop的影子:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
layout="@layout/toolbar_action_bar_shadow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:text="@string/hello_world" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
RES /布局/ …
android android-actionbar android-support-library android-elevation
我的应用程序适用于API 19.所以我不能使用android:elevation.所以我app:在我的布局中提升.
Android XML:android:elevation vs. app:elevation
举个例子 :
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="5dp">
Run Code Online (Sandbox Code Playgroud)
如何以编程方式更改app:elevation?我可以改变android:elevation但我找不到如何更改app:elevation!
今天我开发了我的第一个Android L应用程序,并阅读d.android.com/preview提示.他们说android:海拔会让我看到阴影.但看看这个:
<TextView
android:id="@+id/tvTest5"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@id/btnTest1"
android:layout_toRightOf="@id/tvTest4"
android:layout_marginLeft="10dp"
android:background="#000000"
android:elevation="50dp"/>
Run Code Online (Sandbox Code Playgroud)
我的模拟器中没有看到任何阴影.我做错了什么还是模拟器车?我正在使用Android Studio
我想在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) 我正在尝试ImageButton的应用提升效果.它在我的运行Android 5.0的Nexus平板电脑上运行良好,但是提升不适用于Pre-Lollipop设备.
尝试了ViewCompat.setElevation(view,evaluationValue)但没有改变.
我看到一些应用程序,如Swarm或Gmail应用程序在Pre-Lollipop设备上使用提升效果进行FAB(浮动操作按钮).
你知道他们如何使用海拔吗?
嗨,我正在尝试使用以下代码将阴影应用于线性布局
if (<some condition>)
layout.setElevation(4);
但是此调用需要API级别21才能工作.如何将阴影应用于版本<5.0的设备的布局?可能吗?
我知道这是材料设计的一部分,这就是为什么我只想知道是否有办法在以前的版本中实现类似的东西,谢谢:)