我有一个带有EditText.SoftKeyboard的自定义幻灯片的布局,当我们必须在SLider的EditText中编辑某些内容时,会弹出inputType Number。 一切正常,直到我在布局中添加了一个Spinner,现在编辑文本正在失去焦点,这意味着当我尝试编辑时,不会弹出带有inputType Number的SoftKeyboard。
如果我提交Java代码来设置Spinner,那么EditText工作正常。
我在Manifest中尝试了很多东西,例如adjustPanSize,使用请求焦点,将父布局更改为LinearLayout,似乎没有任何效果。
我粘贴下面的xml和下面的Java代码示例:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_gradient">
<include
android:id="@+id/custom_action_bar"
layout="@layout/custom_action_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonLayout"
android:layout_below="@+id/custom_action_bar"
android:fadeScrollbars="false"
android:isScrollContainer="false"
android:scrollbarSize="@dimen/scrollbar_size"
android:scrollbarThumbVertical="@drawable/scrollbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/screen_bottom_spacing"
android:paddingLeft="@dimen/screen_left_right_spacing"
android:paddingRight="@dimen/screen_left_right_spacing"
android:paddingTop="@dimen/screen_top_spacing">
<include
android:id="@+id/feature_header"
layout="@layout/feature_header" />
<!-- Occupancy enabled -->
<RelativeLayout
android:id="@+id/occupancy_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/feature_header">
<RelativeLayout
android:id="@+id/occupancy_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/field_task_margin_top"
android:orientation="horizontal">
<com.philips.simpleset.view.PhilipsTextView
android:id="@+id/occupancy_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/simple_sensor_occupancy_enabled"
android:textColor="@color/title_color"
android:textSize="@dimen/id_text_size"
app:fontStyle="medium" />
<CheckBox
android:id="@+id/occupancy_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:button="@drawable/checkbox" />
</RelativeLayout>
</RelativeLayout>
<!-- Daylight based control -->
<RelativeLayout
android:id="@+id/daylight_based_control_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/occupancy_container">
<RelativeLayout
android:id="@+id/daylight_based_control_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/field_task_margin_top"
android:orientation="horizontal">
<com.philips.simpleset.view.PhilipsTextView
android:id="@+id/daylight_based_control_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/simple_sensor_daylight_based_control"
android:textColor="@color/title_color"
android:textSize="@dimen/id_text_size"
app:fontStyle="medium" />
<CheckBox
android:id="@+id/daylight_based_control_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:button="@drawable/checkbox" />
</RelativeLayout>
</RelativeLayout>
<!-- Led Indicator -->
<RelativeLayout
android:id="@+id/led_indicator_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/daylight_based_control_container">
<RelativeLayout
android:id="@+id/led_indicator_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/field_task_margin_top"
android:orientation="horizontal">
<com.philips.simpleset.view.PhilipsTextView
android:id="@+id/led_indicator_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/simple_sensor_led_indicator"
android:textColor="@color/title_color"
android:textSize="@dimen/id_text_size"
app:fontStyle="medium" />
<CheckBox
android:id="@+id/led_indicator_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:button="@drawable/checkbox" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/occupancy_mode_layout"
android:layout_below="@+id/led_indicator_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.philips.simpleset.view.PhilipsTextView
android:id="@+id/occupancy_mode_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/occupancy_mode_title"
android:textColor="@color/title_color"
android:textSize="@dimen/id_text_size"
app:fontStyle="medium" />
<Spinner
android:id="@+id/occupancy_mode_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/field_task_margin_top_spinner"
android:layout_below="@+id/occupancy_mode_title" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/sensor_direct_input_slider_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/slider_margin_top"
android:layout_below="@+id/occupancy_mode_layout">
<com.philips.simpleset.view.PhilipsDirectInputSlider
android:id="@+id/field_task_tuning_direct_input_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/slider_margin_top" />
<com.philips.simpleset.view.PhilipsDirectInputSlider
android:id="@+id/eco_level_direct_input_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/field_task_tuning_direct_input_slider"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/field_task_margin_top" />
<com.philips.simpleset.view.PhilipsDirectInputSlider
android:id="@+id/background_light_level_direct_input_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/eco_level_direct_input_slider"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/field_task_margin_top" />
<com.philips.simpleset.view.PhilipsDirectInputSlider
android:id="@+id/hold_time_direct_input_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/background_light_level_direct_input_slider"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/field_task_margin_top" />
<com.philips.simpleset.view.PhilipsDirectInputSlider
android:id="@+id/prolong_time_direct_input_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/hold_time_direct_input_slider"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/field_task_margin_top" />
<com.philips.simpleset.view.PhilipsDirectInputSlider
android:id="@+id/grace_fading_direct_input_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/prolong_time_direct_input_slider"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/field_task_margin_top" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<!--Buttons-->
<LinearLayout
android:id="@+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:paddingBottom="@dimen/screen_bottom_spacing"
android:paddingLeft="@dimen/screen_left_right_spacing"
android:paddingRight="@dimen/screen_left_right_spacing"
android:paddingTop="@dimen/screen_top_spacing">
<com.philips.simpleset.view.PhilipsButton
android:id="@+id/back_btn"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="@dimen/philips_button_height"
android:layout_marginEnd="@dimen/philips_button_horizontal_spacing"
android:layout_weight="1"
android:background="@drawable/philips_button"
android:text="@string/back"
android:textColor="@color/custom_button_text_color_light"
android:textSize="@dimen/philips_button_text_size"
app:fontStyle="regular" />
<com.philips.simpleset.view.PhilipsButton
android:id="@+id/next_btn"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="@dimen/philips_button_height"
android:layout_weight="1"
android:background="@drawable/philips_button"
android:text="@string/confirm"
android:textColor="@color/custom_button_text_color_light"
android:textSize="@dimen/philips_button_text_size"
app:fontStyle="regular" />
</LinearLayout>
</RelativeLayout>
Java代码在这里:
private void initializeView(com.philips.simpleset.core.device.Device device) {
if (NfcAppApplication.getCurrentSubAppType() == SubAppType.EASYSENSE) {
if (device != null) {
textViewUniqueDeviceId.setText(editableProfile.getUniqueId().replaceAll("..(?!$)", "$0 "));
}
imageViewSelectedLuminaire.setImageResource(R.drawable.simple_sensor_icon);
textViewUniqueDeviceId.setVisibility(device == null ? View.GONE : View.VISIBLE);
textViewUniqueDeviceIdTitle.setVisibility(device == null ? View.GONE : View.VISIBLE);
directInputSliderEcoLevel.setVisibility(View.GONE);
layoutOccupancyMode.setVisibility(View.GONE);
} else {
textViewUniqueDeviceIdTitle.setVisibility(View.GONE);
textViewUniqueDeviceId.setVisibility(View.GONE);
}
imageViewSelectedLuminaire.setImageResource(R.drawable.simple_sensor_icon);
directInputSliderFieldTaskTuning.setMin(MIN_FIELD_TASK_TUNING_VALUE);
directInputSliderFieldTaskTuning.setMax(MAX_FIELD_TASK_TUNING_VALUE);
directInputSliderFieldTaskTuning.setSliderUnit("%");
directInputSliderFieldTaskTuning.setSliderLabel(getString(R.string.simple_sensor_field_task_tuning));
directInputSliderHoldTime.setMax(MAX_HOLD_TIME);
directInputSliderHoldTime.setMin(MIN_HOLD_TIME_SLIDER);
directInputSliderHoldTime.setMultiplier(0.5);
directInputSliderHoldTime.setSliderUnit("min");
directInputSliderHoldTime.setSliderLabel(getString(R.string.simple_sensor_hold_time));
directInputSliderProlongTime.setMaxTextViewPresenter(new PhilipsSlider.MaxTextViewPresenter() {
@Override
public String updateTextView() {
return "Infinite";
}
});
directInputSliderProlongTime.setMax(MAX_PROLONG_TIME_SLIDER);
directInputSliderProlongTime.setMin(MIN_PROLONG_TIME_SLIDER);
directInputSliderProlongTime.setSliderUnit("min");
directInputSliderProlongTime.setSliderLabel(getString(R.string.simple_sensor_prolong_time));
directInputSliderBackgroundLightLevel.setMax(MAX_BACKGROUND_LIGHT_LEVEL_SLIDER);
directInputSliderBackgroundLightLevel.setMin(MIN_BACKGROUND_LIGHT_LEVEL_SLIDER);
directInputSliderBackgroundLightLevel.setSliderUnit("%");
directInputSliderBackgroundLightLevel.setSliderLabel(getString(R.string.simple_sensor_background_light_level));
directInputSliderGraceFading.setMax(MAX_GRACE_FADING_SLIDER);
directInputSliderGraceFading.setMin(MIN_GRACE_FADING_SLIDER);
directInputSliderGraceFading.setSliderUnit("s");
directInputSliderGraceFading.setSliderLabel(getString(R.string.simple_sensor_grace_fading));
directInputSliderEcoLevel.setMax(MAX_ECO_LEVEL_SLIDER);
directInputSliderEcoLevel.setMin(MIN_ECO_LEVEL_SLIDER);
directInputSliderEcoLevel.setSliderUnit("%");
directInputSliderEcoLevel.setSliderLabel(getString(R.string.eco_level_title));
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.occupancy_values, R.layout.spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerOccupancyMode.setAdapter(adapter);
spinnerOccupancyMode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
spinnerOccupancyMode.setSelection(position);
occupancyMode = position;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinnerOccupancyMode.setSelection(DEFAULT_OCCUPANCY_MODE);
}
答案 0 :(得分:0)
它相当奇怪但真实! Spinner自定义布局有一个问题,使用android的标准xml解决了这个问题。