用的EditText布局活动,EditText上默认情况下选中 [英] Activity with EditText in layout, EditText is selected by default

查看:110
本文介绍了用的EditText布局活动,EditText上默认情况下选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动用一个简单的布局,一种与的EditText '假'网络浏览器的的URL输入,定义如下:

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
    <的LinearLayout
        机器人:方向=横向
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:paddingTop =10dp
        机器人:paddingLeft =10dp
        机器人:paddingRight =10dp
        机器人:paddingBottom会=6DP
        机器人:背景=@绘制/ activity_title_bar>
    <的EditText
        机器人:ID =@ + ID /地址
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =match_parent
        机器人:layout_weight =1
        机器人:MAXLINES =1
        机器人:scrollHorizo​​ntally =真
        机器人:提示=@字符串/ browser_hint_url
        机器人:文字=@字符串/ browser_url>
    < /&的EditText GT;
    <的ImageButton
        机器人:ID =@ + ID / button_refresh
        机器人:layout_width =50dp
        机器人:layout_height =match_parent
        机器人:SRC =@绘制/ browser_button_refresh>
    < / ImageButton的>
< / LinearLayout中>
<滚动型
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:fillViewport =真正的>
    < ImageView的
        机器人:layout_width =882sp
        机器人:layout_height =1532sp
        机器人:SRC =@绘制/ browser_background>
    < / ImageView的>
< /滚动型>
< / LinearLayout中>

我遇到的问题是,当活动启动时,会默认的EditText 被选中,软键盘激活。我想白白被选中开始,因而不具备软键盘活跃,但无法弄清楚如何通过XML做到这一点。

有什么建议?

谢谢,保罗


解决方案

 的android:windowSoftInputMode = [stateUnchanged,stateHidden
                                       stateAlwaysHidden,stateVisible,
                                       stateAlwaysVisible
                                       adjustResize,>

使用一些这在你的清单,这将隐藏自动键盘弹出。但是,如果您使用某些输入的EditText在时间你需要键盘。 :)

stateHidden 将做的工作。

I have an Activity with a simple layout, a kind of 'faux' web browser with an EditText for the URL input, defined as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="match_parent"
android:layout_height="match_parent">
    <LinearLayout 
        android:orientation="horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="6dp"
        android:background="@drawable/activity_title_bar">
    <EditText 
        android:id="@+id/address" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:maxLines="1"
        android:scrollHorizontally="true"
        android:hint="@string/browser_hint_url"
        android:text="@string/browser_url">
    </EditText>
    <ImageButton
        android:id="@+id/button_refresh"
        android:layout_width="50dp"
        android:layout_height="match_parent" 
        android:src="@drawable/browser_button_refresh">
    </ImageButton>
</LinearLayout>
<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true">
    <ImageView
        android:layout_width="882sp" 
        android:layout_height="1532sp"
        android:src="@drawable/browser_background">     
    </ImageView>
</ScrollView>
</LinearLayout>

The problem I am having is that when the Activity is started, be default the EditText is selected and the soft keyboard activated. I'd like for nothing to be selected to start, and thus not have the soft keyboard active, but can't figure out how to do this via XML.

Any suggestions?

Thanks, Paul

解决方案

android:windowSoftInputMode=[         "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible",
                                       "adjustResize", ] >   

Use some of this in your manifest, this will hide the automatic keyboard pop up. However, if you are using your EditText for some input at time you'll need the keyboard. :)

stateHidden will do the work

这篇关于用的EditText布局活动,EditText上默认情况下选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆