我做了一个按钮,改变了不同状态下的背景,这样:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/btn_location_pressed" /> <!-- pressed -->
<item android:state_focused="true" android:drawable="@drawable/btn_location_pressed"/> <!-- focused -->
<item android:drawable="@drawable/btn_location"/> <!-- default -->
Run Code Online (Sandbox Code Playgroud)
这里的问题是我也试图改变textColor,就像我对drawable一样,但我无法做到.我已经尝试过android:textColor和android:color但是第一个不起作用,而秒数改变了我的背景.
下一个代码是我布局的一部分.关于文本颜色,它仅适用于正常状态文本颜色,因此在按下时不会将其更改为白色
<Button android:id="@+id/location_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:background="@drawable/location"
android:textSize="15sp"
android:textColor="@color/location_color"
android:textColorHighlight="#FFFFFF"
/>
Run Code Online (Sandbox Code Playgroud)
有人有线索吗?
我想要一个简单TextView的运行方式simple_list_item_1在ListView做.这是XML:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:gravity="center" android:focusable="true"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="@android:drawable/list_selector_background" />
Run Code Online (Sandbox Code Playgroud)
一切都有效,除了(预期)在聚焦状态下不会改变的文本颜色.如何将其更改为textAppearanceLargeInverse?
我有这个ListView只需要显示数据.
所以我不想让它可点击.
首先,我尝试将XML listview更改为:
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="false" >
Run Code Online (Sandbox Code Playgroud)
但它没有用.
所以要解决我的问题,我通过代码设置:
list.setSelector(android.R.color.transparent);
Run Code Online (Sandbox Code Playgroud)
但我无法相信没有更好的解决方案.任何的想法?
我只是想知道是否可以简单地删除微调器的下拉箭头?我的旋转器在背景布局中有一个可绘制的箭头,但系统默认箭头出现在旋转器的右侧,我想摆脱它.
这是我的活动布局的微调器xml代码
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinnerSelectStaff"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:gravity="center"
android:dropDownSelector="@drawable/empty"/>
Run Code Online (Sandbox Code Playgroud)
我的自定义微调器布局如下所示:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:textSize="20sp"
android:background="@drawable/spinner_text_shape"
android:drawableRight="@drawable/ic_keyboard_arrow_down_black_24dp"
android:textColor="@color/primary_text" />
Run Code Online (Sandbox Code Playgroud)
谢谢!
android spinner android-layout android-spinner android-selector
我想使用xml为我的tabhost图标着色,而不是以编程方式进行(我无论如何都无法做到这一点)...所以我在SO上找到了这个帖子:Android imageview更改色调来模拟按钮点击
这似乎是一个非常好的解决方案,但我无法在我的项目中正确调整它......我做了以下更改:
public class TintableImageView extends ImageView {
private ColorStateList tint;
public TintableImageView(Context context) {
super(context);
}
//this is the constructor that causes the exception
public TintableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public TintableImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
//here, obtainStyledAttributes was asking for an array
private void init(Context context, AttributeSet attrs, int defStyle) {
TypedArray a = context.obtainStyledAttributes(attrs, new int[]{R.styleable.TintableImageView_tint}, defStyle, 0);
tint = …Run Code Online (Sandbox Code Playgroud) 像下面的东西,但它不起作用.如果我将可绘制颜色切换为蓝色,它可以工作.
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:drawable="@android:color/transparent"/>
</ripple>
Run Code Online (Sandbox Code Playgroud) 我ListView在我的布局中使用了这样的:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:layout_marginTop="5dp"
android:orientation="vertical"
android:layout_centerInParent="true"
android:divider="@color/dark_grey"
android:drawSelectorOnTop="false"
android:focusable="true"
android:layout_marginBottom="55dp"
android:cacheColorHint="#00000000"
android:listSelector="@color/light_grey"
android:dividerHeight="1px" />
Run Code Online (Sandbox Code Playgroud)
选择器工作得很好,但如何禁用选择器?
我试过了:
listView.clearChoices();
listView.setSelected();
listView.setSelector();
...
Run Code Online (Sandbox Code Playgroud)
还有一些东西,但没有任何作用.我有什么想法可以将我选择的项目恢复正常吗?不能那么复杂吧?
编辑:我需要一个程序化的解决方案!
谢谢!
我有一个按钮选择器,可以在按下按钮时更改按钮图像.我还为按钮被禁用时设置了图像.我尝试以编程方式禁用按钮,但禁用的按钮图像没有出现.我的button_selector是否正确?
<item android:drawable="@drawable/red_btn_bg_disabled" android:state_enabled="false"/> <!-- disabled -->
<item android:drawable="@drawable/red_btn_bg_pressed" android:state_pressed="true"/> <!-- pressed -->
<item android:drawable="@drawable/red_btn_bg_pressed" android:state_focused="true"/> <!-- focused -->
<item android:drawable="@drawable/red_btn_bg"/> <!-- default -->
Run Code Online (Sandbox Code Playgroud)
我在我的代码中使用mButton.setEnabled(false)来禁用该按钮
我想在长按时画出选择器,如图所示.当我长按一个项目时,CAB菜单被激活.但是单击后列表选择器指示灯会熄灭一次.我希望列表选择器处于活动状态,直到CAB菜单处于活动状态以允许多个选择.如果我双击,颜色应切换.当我点击它时,这段代码就像闪烁一样.任何人都面临类似的事情?是否有一个hack来实现这个功能?
Gridview有多个选择:

我的OnCreate中的GridView setchoice:
gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
gridView.setMultiChoiceModeListener(new MultiChoiceModeListener());
Run Code Online (Sandbox Code Playgroud)
这很好用:
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
ImageView iv = (ImageView) v
.findViewById(R.id.imageview2);
ViewGroup gridChild = (ViewGroup) gridView
.getChildAt(position);
ViewGroup gridGrandChild = (ViewGroup) gridChild
.getChildAt(0);
ViewGroup gridGreatGrandChild = (ViewGroup) gridGrandChild
.getChildAt(0);
int childSize = gridGreatGrandChild.getChildCount();
if (iv.getId() == gridGreatGrandChild.getChildAt(1)
.getId()) {
if (iv.getVisibility() == 4)
iv.setVisibility(View.VISIBLE);
else
iv.setVisibility(View.INVISIBLE);
}
}});
Run Code Online (Sandbox Code Playgroud)
我试图在激活CAB菜单后在MultiChoiceModeListener()类中实现相同的代码.在里面复制相同的代码
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
}
Run Code Online (Sandbox Code Playgroud)
方法.但我无法访问视图组内的元素.但我能够完整地访问GridView.但不是Grid中的个别孩子. …
当状态被"激活"并且我想保留效果(波纹)时,我想改变我的视图的背景?attr:selectableItemBackground.是否可以扩展或组合选择器?attr:selectableItemBackground?