任何人都可以向我解释如何在CardView中实现Google I/O 2014中展示的一些视觉触摸反馈.
以下是我在XML中使用CardView的方法,可能有一些我想念的小东西,所以我只是想知道是否有人可以帮助我?
<!-- A CardView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/CardView_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
card_view:cardCornerRadius="4dp"
android:elevation="2dp">
<LinearLayout
android:id="@+id/LinearLayout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:onClick="RunSomeMethod"">
<!-- Main CardView Content In Here-->
</LinearLayout> </android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud) android android-layout android-cardview android-5.0-lollipop
在最新的Android SDK中我们现在有了新的CardView,我用新版本替换了我的旧版CustomCardView,但是在旧版本的Android上运行时,我看到state_pressed&state_focused丑陋的正方形显示在CardView上方...
有没有人知道如何在新的CardView中模拟以下内容,但仅限于使用旧版本的Android?
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:enterFadeDuration="150"
android:exitFadeDuration="150" >
<item android:state_pressed="true"
android:drawable="@drawable/card_on_press"/>
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/card_on_focus"/>
<item android:state_enabled="true"
android:drawable="@drawable/card_default"/>
<item android:state_enabled="false"
android:drawable="@drawable/card_on_press"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
对于那些您感兴趣的人,我现在正在使用的是CardView:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:foreground="?android:attr/selectableItemBackground"
android:onClick="RunSomeMethod"
card_view:cardCornerRadius="4dp"
android:focusable="true"
android:elevation="2dp">
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="false"
android:visibility="visible">
</LinearLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud) 对于早期的L Preview,有一些示例如下所示添加到您的代码中以使用FAB(浮动操作按钮).
但不幸的是,我不能使用相同的代码来实现FAB,因为不再支持setOutline方法,但它似乎已被替代方法'fab.setOutlineProvider(ViewOutlineProvider);'所取代.任何人都可以解释如何使用它?...
这可能是我想念的非常简单,但任何帮助都会非常感激.
// Outline
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
Outline outline = new Outline();
outline.setOval(0, 0, size, size);
Button fab = (Button) findViewById(R.id.fab);
fab.setOutline(outline);
fab.setClipToOutline(true);
Run Code Online (Sandbox Code Playgroud) android android-appcompat android-layout material-design android-5.0-lollipop
当我尝试启动活动意图时,Android-O 中的新 ActivityOptions setLaunchDisplayId (int launchDisplayId) 函数似乎总是使我的应用程序崩溃。
当我从我自己的应用程序启动活动时,以及当我尝试启动其他应用程序(例如 Chrome Canary)时。
有谁知道这是新 API 的普遍问题还是我遗漏了什么:
我的代码的一小段如下:
options.setLaunchDisplayId(1);
startActivity(intent, options);
注意 我正在测试启用“模拟第二个屏幕”(@1080p,如果重要的话)。
更新
我已经尝试了 ADB 命令adb shell start com.chrome.canary --display 1,我收到了消息:
开始:必须是root
在 Android-O 中,<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />该应用似乎无法显示在“具有使用权限的应用”列表中。我已尝试将目标和编译 API 设置为 25 和“O”,但仍然无法将应用程序添加到使用访问列表中。
我不确定这是否仅仅是因为开发预览有问题,或者谷歌对 Android-O 中的此功能有其他要求。但是当我在那里测试它时它出现在我的牛轧糖测试设备上,当然编译和目标都设置为 25,因此我在 Android-O 设备上尝试了这些设置来检查它是操作系统还是SDK 有问题,但似乎可能是操作系统。无论如何,我想我应该在这里问一下,看看我是否遗漏了你们可能知道的东西。