如何使图形的孩子的TextView白当STATE_ pressed ="真" [英] How to make shape's child TextView white when state_pressed="true"
问题描述
这形状是的LinearLayout的底色,我怎么能做出的LinearLayout内的任何TextViews状态$ P $过程中更改它们的文本颜色为白色pssed =家长选择的是真的吗?另见我的previous问题多看看code的:形状不显示一>
<形状
的xmlns:机器人=http://schemas.android.com/apk/res/android>
[固体
机器人:颜色=#FFFFFF/>
<中风
机器人:宽=1DP
机器人:颜色=#AA000000/>
<角落
机器人:topLeftRadius =10dp
机器人:topRightRadius =10dp/>
<梯度
机器人:startColor =#6633cc
机器人:ENDCOLOR =#00CCFF
机器人:角=270/>
< /形状>
pressed状态传播到布局的所有子视图。你可以声明的颜色状态列表类似你如何声明可绘制的状态列表。如果设置父内文本的状态列表颜色变成pressed中,pressed国家将适用于文本颜色为好。
编辑:报价信息是部分不正确,被别人编辑的:
使用:机器人:duplicateParentState =真为TextView的,也
用途:机器人:颜色=@色/ myNewColor
块引用>此XML彩色文件被放置在一个项目的RES /彩色目录。
下面是从AOSP,用于默认文本的例子:<一href=\"http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/color/primary_text_dark.xml;h=f0812edbadcbcf6cd1a887b374ce7b6209e7d1b8;hb=HEAD\" rel=\"nofollow\">http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/color/primary_text_dark.xml;h=f0812edbadcbcf6cd1a887b374ce7b6209e7d1b8;hb=HEAD
编辑:您编辑我的答案不正确的信息。不管了Android的pressed状态传播。duplicateParentState设置
View.java,设置pressed方法调用dispatchSet $ P $ pssed:
<一href=\"http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/View.java;h=232dd6a8f63f4a3405053211d37e29c8a418ccc1;hb=HEAD#l3361\" rel=\"nofollow\">http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/View.java;h=232dd6a8f63f4a3405053211d37e29c8a418ccc1;hb=HEAD#l3361ViewGroup.java,重写的dispatchSet $ P $ pssed方法将所有子视图pressed:
<一href=\"http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/ViewGroup.java;h=2b71b4a492e04d13cf46d5a1eee91f8a43f89112;hb=HEAD#l1710\" rel=\"nofollow\">http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/ViewGroup.java;h=2b71b4a492e04d13cf46d5a1eee91f8a43f89112;hb=HEAD#l1710This shape is the backround of a linearLayout, how can I make any TextViews within the LinearLayout change their text color to white during the statePressed =true of the parent selector? Also see my previous question to see more of the code: Shape does not show
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFF" /> <stroke android:width="1dp" android:color="#AA000000" /> <corners android:topLeftRadius="10dp" android:topRightRadius="10dp" /> <gradient android:startColor="#6633cc" android:endColor="#00ccff" android:angle="270" /> </shape>
解决方案Pressed state is propagated to all child views of a layout. You can declare a state list of colors similarly to how you declare a state list of drawables. If you set a state list color on text within a parent that becomes pressed, the pressed state will apply to the text color as well.
EDIT: The quoted information is partially incorrect and was edited in by someone else:
USE: android:duplicateParentState="true" for the TextView, also USE: android:color="@color/myNewColor"
This XML color file is placed in the res/color directory of a project.
Here's an example from AOSP, used for default text: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/color/primary_text_dark.xml;h=f0812edbadcbcf6cd1a887b374ce7b6209e7d1b8;hb=HEAD
EDIT: You edited my answer with incorrect information. Pressed state is propagated regardless of the android:duplicateParentState setting.
View.java, the setPressed method invokes dispatchSetPressed: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/View.java;h=232dd6a8f63f4a3405053211d37e29c8a418ccc1;hb=HEAD#l3361
ViewGroup.java, the overridden dispatchSetPressed method sets all child views pressed: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/view/ViewGroup.java;h=2b71b4a492e04d13cf46d5a1eee91f8a43f89112;hb=HEAD#l1710
这篇关于如何使图形的孩子的TextView白当STATE_ pressed =&QUOT;真&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!