- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在最新的 Android SDK 中,我们现在有了新的 CardView,我用新版本替换了旧的 CustomCardView,但是在旧版本的 Android 上运行时,我看到 state_pressed
& state_focused
是显示在 CardView 上方的丑陋方 block ...
有谁知道我如何在新的 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>
对于那些感兴趣的人,这里是我现在使用的 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>
最佳答案
使用以下代码修复:
values-v21\styles.xml:
<style name="CardViewStyle" parent="CardView.Light">
<item name="android:foreground">?android:attr/selectableItemBackground</item>
</style>
值\styles.xml:
<style name="CardViewStyle" parent="android:Widget.TextView">
<item name="android:foreground">@drawable/card</item>
</style>
来自 layout\main_layout.xml 的卡片:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/Card_View"
style="@style/CardViewStyle"
android:layout_width="480dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
card_view:cardCornerRadius="4dp"
android:elevation="2dp">
这将允许您在 v21+ 中提供动画,但也在 v21 之前的版本中提供替代动画,而不是大的蓝色/灰色方 block 。
这是我用作可绘制对象的 card.xml,供您感兴趣:
<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>
注意:Drawable default 将作为透明项目很好,因为 CardView 为所有 android 版本提供了默认背景。
关于android - 为旧版本的 Android 覆盖 Android-L CardView state_pressed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24518376/
我使用 xml 文件为我的按钮着色。在 xml 中有这个代码来定义我的按钮被点击时的颜色。
我在 res/drawable 中有以下 XML 代码,我将按钮 background 设置为此 drawable。但是,当我按下按钮时,它并没有改变 color。感谢帮助 最佳答案 好吧
我已经创建了自己的 android 主题来更改操作栏选项卡的外观。问题在于 textcolor 选择器似乎忽略了 state_pressed 属性,因此即使按下此选项卡,选项卡文本的颜色也始终相同。其
我下面的自定义选择器没有按预期工作,我根本看不到 pressed 状态。任何提示?谢谢 最佳答案 尝试像这样将 state_pressed 移动
我有这样的 RelativeLayout: 看起来像: 我的 contacts 选择器似乎: 如您所见,我有 3 张图片:默认情况下,选中并按下。 但我有一个问题:只有默认
谁能解释(或指向解释的链接)ListView 项的 state_activated、state_selected、state_pressed 和 state_focused 之间的区别?它们都是 Li
我想在按下时为 ImageView 的背景着色。我尝试使用选择器来更改不同状态(按下和未按下)的图像。现在的问题是图像用完全相同的大小替换了之前的图像,我希望它更大。我使用实现可检查的自定义布局,我还
我正在使用一个选择器来为我的 View 设置动画,其中一个我是这样做的: 查看: 选择器_ GridView : selector_gridview_pressed:
我正在尝试根据其状态更改 TextView 样式。我的 styles.xml 包含: left @color/text_usual_color bold
我正在(尝试)编写一个没有 xml 文件的程序(android 文档说这是可能的)但是我很难找到一些细节的信息。 当项目被中性色触摸时,我想替换丑陋的橙色。 有人知道我们如何在程序中做到这一点吗?对于
我花了很多时间试图解决这个问题,但没有成功。 我基本上是在尝试在单击列表项时更改它们的颜色。 我制作了一个选择器xml文件并将其存储在res/color/red_background.xml
我指的是 https://stackoverflow.com/a/24475228/72437 上的答案 建议的答案是使用来自 Android 的可绘制对象:?android:attr/selecta
如何实现 android:background 同时点击多个 View 的改变效果? 我得到了一个分为两部分的“徽章”布局。它们就像一个按钮,但这两部分有不同的 StateListDrawable(选
我正在尝试自定义 Google map 中 InfoWindow 的 state_pressed 行为。通常当这个信息窗口被按下时,它会变成黄色。自定义 InfoWindows 也是如此。但我想把它改
我想要这个 而且这个好像不支持了。 我想知道是否有另一种方法可以在按下时增加文本大小(在 xml 中)? 非常感谢! 最佳答案 更新代码--创建您自己的 dimens.xml 文件,然后
我有一个问题。首先检查我的代码: 这里,默认文本颜色出现在默认状态。当我单击时,列表项中的文本颜色发生变化。但是当一个项目被选中时文本的颜色不会改变。 我尝试了一些东
我还没有找到解决办法。 我有一个静音/取消静音按钮。我将它设置为一个 ImageButton,src 和背景都是选择器可绘制对象。 我正在展示- 选择按钮时的“静音”图标- 未选择按钮时的“静音”图标
在最新的 Android SDK 中,我们现在有了新的 CardView,我用新版本替换了旧的 CustomCardView,但是在旧版本的 Android 上运行时,我看到 state_presse
我正在将自定义可绘制对象设置为复选框按钮, 但似乎只有 android:state_checked="true" 和 android:state_checked="false" 有效。 其他州不工作。
我是一名优秀的程序员,十分优秀!