Android NumberPicker取消选择号码
我使用了一个稍微修改过的NumberPicker,当活动开始时,默认值已经被选中。这很烦人,因为它会打开键盘或对话框进行剪切/复制/粘贴。我确实指示键盘保持向下,但它仍然处于选中状态,并将弹出“剪切/复制/粘贴”对话框。一旦我滚动浏览这些值,数字就不再被选中,它会正常工作。有人知道如何将NumberPicker设置为在启动时不选择任何内容吗Android NumberPicker取消选择号码,android,numberpicker,Android,Numberpicker,我使用了一个稍微修改过的NumberPicker,当活动开始时,默认值已经被选中。这很烦人,因为它会打开键盘或对话框进行剪切/复制/粘贴。我确实指示键盘保持向下,但它仍然处于选中状态,并将弹出“剪切/复制/粘贴”对话框。一旦我滚动浏览这些值,数字就不再被选中,它会正常工作。有人知道如何将NumberPicker设置为在启动时不选择任何内容吗 @TargetApi(Build.VERSION_CODES.HONEYCOMB) public class NumPicker extends Numbe
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class NumPicker extends NumberPicker
{
public NumPicker(Context context)
{
super(context);
}
public NumPicker(Context context, AttributeSet attrs)
{
super(context, attrs);
processAttributeSet(attrs);
}
public NumPicker(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
processAttributeSet(attrs);
}
/**
* Reads the xml, sets the properties
*/
private void processAttributeSet(AttributeSet attrs)
{
setMinValue(attrs.getAttributeIntValue(null, "min", 0));
setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
setValue(4);
}
}
以下是它在xml中的使用方式:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginRight="50dp"
android:layout_marginEnd="50dp"
android:layout_marginTop="40dp"
style="@style/CustomText"
max="100"
min="2"
发生这种情况的原因是NumberPicker是活动中第一个(或唯一一个)可聚焦的元素。通过将此属性添加到根视图,可以将焦点捕获到主布局视图:
android:focusableInTouchMode="true"
我在NumPicker类和我的活动中尝试了clearFocus()。这两个都没什么不同。是的,它起作用了,谢谢你。我试着将焦点转移到文本视图或按钮上,但我想这是不可能的。