在布局中使用EditText的活动,默认情况下选择EditText

时间:2011-07-20 20:33:08

标签: android android-layout

我有一个简单布局的Activity,一种带有EditText的“虚假”网络浏览器,用于输入网址,定义如下:

<?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>

我遇到的问题是,当Activity启动时,默认选择EditText并激活软键盘。我希望没有什么可以选择启动,因此没有激活软键盘,但无法弄清楚如何通过XML实现这一点。

有什么建议吗?

谢谢,保罗

2 个答案:

答案 0 :(得分:1)

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

在清单中使用其中一些,这将隐藏弹出的自动键盘。但是,如果您正在使用EditText进行某些输入,则需要使用键盘。 :)

stateHidden将完成工作

答案 1 :(得分:0)

获取对其他视图的引用,可以是ImageButton,也可以是LinearLayout。然后在你的onCreate()方法中调用非EditText视图上的view.requestFocus();,它将窃取焦点并保持键盘不被显示。