【问题标题】:Android Text Input Special UI ItemAndroid 文本输入特殊 UI 项
【发布时间】:2011-07-21 00:54:16
【问题描述】:

我正在为 Android 操作系统创建一个 IM 客户端/服务器应用程序,并且目前正在整合用户界面。现在,我的界面由一个EditText 元素和一个Button 元素组成。当我点击EditText 元素时,会弹出一个键盘并允许您输入。

我想要的是默认 Android SMS 应用程序中的文本输入区域和发送按钮。像这样的东西: 文本输入字段和发送按钮将留在屏幕底部,当点击时,键盘会将文本字段和按钮向上推。

这是否可能仅使用 EditTextButton 元素?

感谢您的任何建议或意见!

【问题讨论】:

    标签: android user-interface button keyboard android-edittext


    【解决方案1】:

    尝试为 AndroidManifest.xml 中的活动设置android:windowSoftInputMode=adjustResize

    您可以找到详细信息here

    【讨论】:

    • 感谢您的回复。我在清单文件中添加了 android:windowSoftInputMode="adjustResize"` 并开始工作。如果有人感兴趣,我还使用了stackoverflow.com/questions/2386866/… 中的相对布局。谢谢!
    【解决方案2】:

    这可能只使用 EditText 和 Button 元素吗?

    Answer-这种类型的功能在任何类型的视图中都是可能的

    我只是针对您的问题提供简短的教程 通常我们在 xml 文件中只使用线性布局。但是在视图级别,android 提供了更多功能,例如相对布局等等。此时我们只讨论相对布局,因为它可以解决您的目的。

    在相对布局中,它不像线性布局那样使用 android:orientation 特性,它使用了另一个特性。在相对布局中,请记住一些要点...

    1. 我们总是使用 android:id="@+id/GiveName" 为每个视图分配 ID
    2. 对于我们使用的任何视图的对齐 android:layout_toLeftOf="@id/givesname" 相同
      右,上方和下方 givesname=id 与该视图对齐的视图

      例如。是gives example with screen shot

      在此之后,我给出了示例 xml 文件,您可以在其中获得问题中的上述类型的功能

      <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/llWriteCommentWall" android:layout_height="fill_parent"
          android:layout_width="fill_parent" android:background="#ffffff">
          <Button android:id="@+id/btButtonComments"
            android:layout_height="wrap_content"     
            android:layout_width="wrap_content"        
            android:text="Comments" 
            android:layout_alignParentRight="true"  
            android:layout_alignParentBottom="true"/>
          <EditText android:id="@+id/etEdittext"
            android:layout_height="wrap_content" android:layout_width="fill_parent"
            android:hint="Write a comment....   "
            android:layout_marginLeft="2dip" android:layout_marginRight="2dip" 
            android:layout_toLeftOf="@id/btButtonComments" 
            android:layout_alignParentBottom="true"/>
        </RelativeLayout>
    

    以上示例的截图

    在这个例子中,我们使用了 android:layout_alignParentBottom="true" - 这个属性是这种视图的主要原因,它总是对齐底部的任何视图,即使软键盘显示。它包含布尔值,true 总是对齐底部,false 什么都没有。

    另一个相关属性是 android:layout_alignParentRight="true",android:layout_alignParentLeft="true" ,android:layout_alignParentTop="true"-所有属性都给出了所写的功能。

    最后通过 setContentView(xmlFileName) 将这个 xml 文件包含在任何 java 文件中

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多