0

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

Unpossible
  • 10,607
  • 22
  • 75
  • 113

2 Answers2

1
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

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
  • This was it, but also including the `android:focusable="true" android:focusableInTouchMode="true"` for the parent LinearLayout as per citizen conn's suggestion above. – Unpossible Jul 20 '11 at 20:46
0

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.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156