我需要弄清楚为什么我一直在显示Android键盘,因为我的 EditText 并且enabled属性设置为false。我的布局文件的根元素是 ScrollView 。当我取出ScrollView元素时,它与LinearLayout等根元素完美配合。
这是ScrollView的预期行为,还是只是一个有问题的东西? (如果是这种情况,我不明白让ScrollView具有文本可编辑元素行为。)
另外,我的一些布局代码......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lorem ipsum dolor sit amet"
android:layout_marginBottom="20dp"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/input_name_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_idcard_icon"
/>
<EditText
android:id="@+id/personal_setting_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/input_name_icon"
android:enabled="false"
android:text="First Name" />
不要紧张,我会正确地改变我的弦乐和尺寸......; D
答案 0 :(得分:0)
如果您想避免每次使用ScrollView打开活动时都显示Android键盘,则必须放置android:focusableInTouchMode="true"
但不要放在EditText中。你必须把它放在ScrollView中:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="copsonic.com.SoundExchange.demoApp.FragmentTransmitter">
<!-- Common template for all fragments -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:focusableInTouchMode="true">
<EditText
android:id="@+id/editTextmessage2Send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/button_send_msg"
android:ems="10"
android:hint="@string/edit_message" >
</EditText>
</RelativeLayout>
</ScrollView>