以文字输入方式最多可输入2000个字符的最佳方式android应用
我的应用程序应该能够显示一些对话框或活动,以便从用户接收文本输入。随着确定和取消按钮以文字输入方式最多可输入2000个字符的最佳方式android应用
我尝试2种方式 与自定义布局即EditText上,确定1.警告对话框,并取消按钮 但是,一旦用户点击OK,的onClick()事件只接受最终的字符串。从Main活动调用警报对话框,但在Utils类中编写的代码表示Utils.showDialog()。
一旦对话获取数据,我需要将编辑文本字符串传递回调用util.showdialog()的MainActivity。
其他方法 2.从MainActivity开始,带有编辑文本的新活动,ok和取消布局。一旦用户点击确定,在活动中,我得到字符串并处理它。布局是在OK和CANCEL按钮下方的编辑文本。
这样做的一个问题是,我将字符数限制为2000,当我输入的文字超过手机屏幕(比如5英寸)时,OK取消按钮正在关闭,无法访问OK和CANCEL按钮。
如果我需要使用第二个方法,我应该能够解决好,并在底部和编辑文本CANCEL按钮上面应能上下移动。
我该如何做到这一点,哪一个是合适的?
布局应该是这样的第二方法
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="2000" />
</ScrollView>
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="OK" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
我试过这种布局,但是当数据进入超出屏幕限制时,OK和取消按钮就不见了。我希望两个按钮都应该在底部可见,编辑文本视图应该能够滚动。使用上面的编辑文本可以滚动,但按钮停止可见超过几行输入。 –
@Sudarshansridhar为你的'LinearLayout'添加一个'android:id'属性,称之为'linearLayoutId',然后将下面的行添加到'ScrollView' - 'android:layout_above =“@ + id/linearLayoutId”' – PPartisan
你可以只编程修复对话框的大小: alertDialog.getWindow()的setLayout(600,400); //控制宽度和高度。 – Ahmed