EditText提示信息无法消失

4
问题:在可以处理我的两个窗格Fragment容器以便将列表视图和选定视图并排显示的设备上,EditView android:hint当输入文字时会隐藏。然而,在Motorola XOOM和Nexus 7上,android:hint在插入文本时不会消失。
更新:我已经解决了ListView调整大小的问题。由于重绘,只是看起来ListView没有调整大小。然而,我的问题仍然存在,就是EditText无法隐藏android:hint。我已经添加了一个更新后的代码和问题截图。为了记录目的,我将保留旧内容,除非其他人认为应该删除。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/contact_detail_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/chat_camera_button"
            style="android:selectableItemBackground"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/camera_button" />

        <ImageButton
            android:id="@+id/chat_text_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_toLeftOf="@+id/chat_record_button"
            android:background="?android:attr/selectableItemBackground"
            android:src="@drawable/send_text_button" />

        <ImageButton
            android:id="@+id/chat_record_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@android:color/transparent"
            android:focusableInTouchMode="true"
            android:longClickable="true"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:src="@drawable/mic_disabled" />

       <EditText
           android:id="@+id/chat_message_text"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentBottom="true"
           android:layout_toLeftOf="@+id/chat_text_button"
           android:layout_toRightOf="@+id/chat_camera_button"
           android:ems="10"
           android:hint="@string/message_hint"
           android:inputType="textMultiLine|textCapSentences"
           android:maxLines="3"
           android:minLines="1" />

        <ListView
            android:id="@+id/messages_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/chat_message_text"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:stackFromBottom="true"
            android:transcriptMode="alwaysScroll" />

</RelativeLayout>
< p >更新[旧版]:这似乎只局限于我在家里测试的 Droid RAZRs。我已经测试了3个。还有其他人在 Droid RAZR 上遇到问题吗?< /p> < p >我正在尝试让我的列表视图(List-view)和编辑文本(Edit-text)随着用户输入更多行(最多3行)而重新调整大小。然而,由于某种原因,提示(hint)没有消失,而列表视图(List-view)也没有重新调整大小。< /p> < p >此外,在我的编辑文本(Edit-text)中使用的 android:hint 不会在有文字时消失。< /p> < p >以下是错误图片的示例(忽略发送按钮,我不再调整它)< /p> < p >需要图片的人可以点击这里查看:http://i.stack.imgur.com/e7FJJ.png< /p>
Black - ListView

White - EditText + Button

Green - Text inside EditText

以下是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/contact_detail_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

        <Button
            android:id="@+id/details_record_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text="Send" />

       <EditText
           android:id="@+id/chat_message_input"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentBottom="true"
           android:layout_alignParentLeft="true"
           android:layout_toLeftOf="@+id/details_record_button"
           android:ems="10"
           android:hint="@string/message_hint"
           android:paddingRight="10dp"
           android:paddingTop="10dp"
           android:inputType="textMultiLine"
           android:minLines="1"
           android:maxLines="3"
           android:textColor="#00FF00"/>

        <ListView
            android:id="@+id/messages_list"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/chat_message_input"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:background="#000000" />

</RelativeLayout>

你尝试过将ListView的高度设置为“wrap_content”吗? - Bill Mote
是的,我也已经尝试过那个了。 - Rijvi Rajib
它对我来说运作良好。你在设备上测试过吗? - Ishtiaq
我正在Droid RAZR上进行测试。另外,如果Activity在FragmentActivity内部,这会有影响吗? - Rijvi Rajib
3个回答

4

我的情况是由于我膨胀了多个相同布局的层。例如,在我的活动的onCreate中,我正在做这件事:

setContentView(R.layout.activity_login);

在我的片段中,同时也要执行这个动作:
View view = inflater.inflate(R.layout.activity_login, container, false);
...
return view;

这将创建两个完美重叠的控件。因此,当您在EditText控件中输入文本时,您只需将其输入到其中一个控件中。因此,其中一个显示您键入的文本,而另一个则为空且未聚焦,正确地显示提示。

因此解决方案是从活动或所有片段中删除布局。


1
在你的editText中添加一个TextWatcher,当你看到文本不等于""时,将提示文本设置为""。
et1.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {

            // MAKE CHANGES TO YOUR EDITTEXT HINT TEXT HERE
        }
    });

0

这只是由于多次安装 APK 和启动应用程序导致的问题。在模拟器或设备中卸载 APP,它应该解决问题。

您可以尝试按返回按钮并重新启动应用程序,以确保您没有多个片段实例。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接