开发者

Activity with EditText in layout, EditText is selected by default

开发者 https://www.devze.com 2023-03-22 00:34 出处:网络
I have an Activity with a simple layout, a kind of \'faux\' web browser with an EditText for the URL input, defined as follows:

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"
and开发者_如何学Goroid: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


get a reference to one of your other views, either the ImageButton, or the LinearLayout. Then in your onCreate() method call view.requestFocus(); on the non-EditText view and it will steal focus away and keep the keyboard from being shown.

0

精彩评论

暂无评论...
验证码 换一张
取 消