I created one registration page using relative layout and applied background image to main layout. Here I used scroll view for scrolling my contents.
Problem: when I selected my textfield, background image of main relative layout stretched.
Here is my xml content:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:androidcustomfont="http://schemas.android.com/apk/res/com.cpt.realtor.activity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="615dp" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="680dp" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="25dp"
android:src="#drawable/realtor_land_text" />
<EditText
android:id="#+id/editFirstName"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/firstname"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editLastName"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editFirstName"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/lastname"
android:inputType="textPersonName" />
<EditText
android:id="#+id/editCompany"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editLastName"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/company"
android:inputType="text" />
<EditText
android:id="#+id/editMobile"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editCompany"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/mobile"
android:imeOptions="actionDone"
android:inputType="phone"
android:maxLength="10" />
<EditText
android:id="#+id/editEmail"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editMobile"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/email"
android:inputType="textEmailAddress" />
<Spinner
android:id="#+id/spinnerForStates"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editEmail"
android:layout_marginLeft="40dp"
android:layout_marginTop="10dp" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinnerForStates"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp"
android:button="#drawable/checkbox_selector"
android:text="#string/receivealert"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<com.cpt.realtor.utility.CustomFontButton
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/checkBox"
android:layout_marginLeft="180dp"
android:layout_marginTop="10dp"
android:background="#drawable/share_btn_selector"
android:text="#string/submit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"
androidcustomfont:customFontView="clarendon_regular.ttf" />
<TextView
android:id="#+id/textSkip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/submit"
android:layout_marginLeft="205dp"
android:layout_marginTop="8dp"
android:textSize="15sp"
android:text="#string/skip_this_step"
android:textColor="#color/white" />
<View
android:id="#+id/splitter"
android:layout_width="93dp"
android:layout_height="1dip"
android:layout_below="#+id/textSkip"
android:layout_marginLeft="210dp"
android:layout_marginTop="0dp"
android:background="#color/white" />
<View
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/textSkip"
android:background="#drawable/footer" />
</RelativeLayout>
</ScrollView>
without selecting TextField:
After selecting TextField:
In my second image, the background image stretched. How can I solve this?
In your manifest write this in activity tag
android:windowSoftInputMode="stateVisible|adjustPan"
Related
Here is the form that I made in the XML:
Here the output when I run it on an emulator:
Does any one know how to make the emulator have the same style as the XML page?
I'm using nexus 6 emulator and the following. Is my XML code. I have added in manifest part a support element, but I still have the problem.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".signupActivity"
android:background="#color/white">
<EditText
android:id="#+id/input_name"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="138dp"
android:backgroundTint="#D3D3D3"
android:fontFamily="sans-serif"
android:hint="Name"
android:textColor="#7c7a7a"
android:textColorHint="#A9A9A9" />
<!-- email text field -->
<EditText
android:id="#+id/input_email"
android:layout_width="306dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="201dp"
android:backgroundTint="#D3D3D3"
android:fontFamily="sans-serif"
android:hint="Email"
android:inputType="textEmailAddress"
android:textColor="#7c7a7a"
android:textColorHint="#A9A9A9" />
<!-- phone text field -->
<EditText
android:id="#+id/phoneNO"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="141dp"
android:backgroundTint="#D3D3D3"
android:fontFamily="sans-serif"
android:hint="phone number"
android:inputType="phone"
android:textColor="#7c7a7a"
android:textColorHint="#A9A9A9" />
<EditText
android:id="#+id/input_password"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:backgroundTint="#D3D3D3"
android:fontFamily="sans-serif"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#7c7a7a"
android:textColorHint="#A9A9A9" />
<!-- login block -->
<TextView
android:id="#+id/link_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="22dp"
android:layout_weight="1"
android:gravity="center"
android:text="Already a member? Login"
android:textColor="#6F73FF"
android:textSize="16dip" />
<!-- password text field -->
<EditText
android:id="#+id/input_password2"
android:layout_width="302dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="202dp"
android:backgroundTint="#D3D3D3"
android:fontFamily="sans-serif"
android:hint="confirm password"
android:inputType="textPassword"
android:textColor="#7c7a7a"
android:textColorHint="#A9A9A9" />
<!-- Signup Button -->
<Button
android:id="#+id/btn_signup"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="64dp"
android:background="#drawable/edit_rouded"
android:fontFamily="sans-serif"
android:padding="12dp"
android:text="Create Account" />
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="73dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#6F73FF"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="Sign Up"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="24sp" />
<ImageView
android:layout_width="30dp"
android:layout_height="38dp"
android:layout_alignBottom="#+id/phoneNO"
android:layout_toStartOf="#+id/input_name"
android:adjustViewBounds="false"
android:src="#drawable/ic_call_black_24dp"
tools:layout_editor_absoluteX="20dp"
tools:layout_editor_absoluteY="267dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="38dp"
android:layout_alignTop="#+id/input_password2"
android:layout_toStartOf="#+id/input_name"
android:adjustViewBounds="false"
android:src="#drawable/ic_lock_outline_black_24dp"
tools:layout_editor_absoluteX="20dp"
tools:layout_editor_absoluteY="267dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="38dp"
android:layout_alignTop="#+id/input_password"
android:layout_toStartOf="#+id/input_name"
android:adjustViewBounds="false"
android:src="#drawable/ic_lock_outline_black_24dp"
tools:layout_editor_absoluteX="20dp"
tools:layout_editor_absoluteY="267dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="43dp"
android:layout_alignTop="#+id/input_email"
android:layout_toStartOf="#+id/input_name"
android:adjustViewBounds="false"
android:src="#drawable/ic_mail_outline_black_24dp"
tools:layout_editor_absoluteX="20dp"
tools:layout_editor_absoluteY="267dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="38dp"
android:layout_alignBottom="#+id/input_name"
android:layout_toStartOf="#+id/input_name"
android:adjustViewBounds="false"
android:src="#drawable/ic_perm_identity_black_24dp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="267dp" />
</RelativeLayout>
I have changed the layout from absolute to relative but I still have the problem.
You are setting up the elements by placing margins. this will not work perfectly on all devices. Rather please use appropriate layout and implement the design
Ex: Create a linear layout with a vertical orientation and add the elements. This will scale with all kinds of screens. Additionally, keep the main layout inside a scroll view. this will help in very small screens
I tried adding android:windowSoftInputMode in AndroidManifest.xml file and
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
both of them are not working.Even tried adding some WorkAround code from stack Overflow.Nothing is changing.
In my xml i used RelativeLayout which is wrapped under ScrollView. The scrollview contains only one child i.e. RelativeLayout
Please help me to do it.I have been stuck with this issue for long time.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="ca.com.helptree.Activities.LoginActivity">
<ImageView
android:id="#+id/imglogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="62dp"
app:srcCompat="#drawable/appicon" />
<TextView
android:id="#+id/txtAppName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imglogo"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="#string/app_Uname"
android:textColor="#color/colorBlack"
android:textSize="20sp" />
<TextView
android:id="#+id/tvCCode"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtAppName"
android:layout_marginStart="25dp"
android:layout_marginTop="26dp"
android:background="#xml/rounded_corner"
android:ems="10"
android:gravity="center"
android:hint="+Code"
android:text=""
android:textAlignment="center"
android:textColor="#color/colorBlack" />
<EditText
android:id="#+id/etxtMobileNo"
android:layout_width="225dp"
android:layout_height="30dp"
android:layout_alignTop="#+id/tvCCode"
android:layout_marginStart="26dp"
android:layout_toEndOf="#+id/tvCCode"
android:background="#xml/rounded_corner"
android:ems="10"
android:gravity="center"
android:hint="Mobile No"
android:inputType="phone"
android:textColor="#color/colorBlack" />
<android.support.design.widget.TextInputLayout
android:id="#+id/txtILayout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignEnd="#+id/etxtMobileNo"
android:layout_below="#+id/tvCCode"
android:layout_marginStart="25dp"
android:layout_marginTop="13dp"
android:textAlignment="center"
app:hintEnabled="false"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/etxtPassword"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#xml/rounded_corner"
android:gravity="center"
android:hint="Password"
android:inputType="textPassword"
android:textAlignment="center"
android:textColor="#color/colorBlack" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/btnSignup"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/txtILayout"
android:layout_below="#+id/txtILayout"
android:layout_marginTop="11dp"
android:background="#xml/signup_button"
android:text="#string/Signup"
android:textColor="#color/colorWhite" />
<Button
android:id="#+id/btnSignin"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/txtILayout"
android:layout_alignTop="#+id/btnSignup"
android:background="#xml/signin_button"
android:text="#string/Signin"
android:textColor="#color/colorWhite" />
</RelativeLayout></ScrollView>
On your AndroidManifest.xml file put this last line
<activity
android:name="at.next.neah.screens.service.activitys.MY_Activity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize" /> <<<<<<<<<<<<<<<
I am making an android app..
In My xml file I have tried the below code:--
activity_registration
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/blue">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txt22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dubai Tour and Travels"
android:textColor="#color/white"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:typeface="monospace"
android:layout_gravity="center"/>
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10sp"
android:background="#color/shadow"
android:paddingLeft="15dip"
android:paddingRight="15dip">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#color/black"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:typeface="monospace"/>
<EditText
android:id="#+id/fieldFirstOpinion"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:minHeight="10sp"
android:hint="Name"/>
<TextView
android:id="#+id/tx2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email Id"
android:textColor="#color/black"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:typeface="monospace"/>
<EditText
android:id="#+id/ed2"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:minHeight="10sp"
android:hint="Email id"/>
<TextView
android:id="#+id/tx3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile Number"
android:textColor="#color/black"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:typeface="monospace"/>
<EditText
android:id="#+id/ed3"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:minHeight="10sp"
android:hint="Mobile Number"
android:inputType="number"/>
<TextView
android:id="#+id/tx4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile Number"
android:textColor="#color/black"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:typeface="monospace"/>
<Spinner
android:id="#+id/spinner1"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"/>
<TextView
android:id="#+id/tx5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textColor="#color/black"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:typeface="monospace"/>
<EditText
android:id="#+id/ed4"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:minHeight="10sp"
android:hint="Address" />
<Button
android:id="#+id/button1"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="Submit" />
</LinearLayout>
</ScrollView>
In this code I am getting my all data.
But I want the font and the style view as like:--That example page
In this page the textviews,edittext,button,spinner are arranged in a good way.they are very small size..
How can I achieve that??
It seems in your screenshot they used #android:drawable/editbox_background as EditText's background. You have to create a rounded corner button in xml and placed that in drawable folder.
Solution 1 :
create a folder named drawable inside res folder in your project.
create a xml file inside that drawable folder named
rounded_corner_btn
rounded_corner_btn xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/yellow" />
<corners
android:bottomLeftRadius="24dp"
android:bottomRightRadius="24dp"
android:topLeftRadius="24dp"
android:topRightRadius="24dp" />
</shape>
activity_registration xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/blue" >
<TextView
android:id="#+id/txt22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Dubai Tour and Travels"
android:textColor="#color/white"
android:textStyle="bold"
android:typeface="monospace" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:background="#color/wallet_highlighted_text_holo_dark"
android:orientation="vertical"
android:paddingLeft="15dip"
android:paddingRight="15dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Name"
android:textColor="#color/black"
android:textStyle="bold"
android:typeface="monospace" />
<EditText
android:id="#+id/fieldFirstOpinion"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:hint="Name"
android:minHeight="10sp"
android:background="#android:drawable/editbox_background" />
<TextView
android:id="#+id/tx2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Email Id"
android:textColor="#color/black"
android:textStyle="bold"
android:typeface="monospace" />
<EditText
android:id="#+id/ed2"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:hint="Email id"
android:minHeight="10sp"
android:background="#android:drawable/editbox_background" />
<TextView
android:id="#+id/tx3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Mobile Number"
android:textColor="#color/black"
android:textStyle="bold"
android:typeface="monospace" />
<EditText
android:id="#+id/ed3"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:hint="Mobile Number"
android:inputType="number"
android:minHeight="10sp"
android:background="#android:drawable/editbox_background" />
<TextView
android:id="#+id/tx4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Mobile Number"
android:textColor="#color/black"
android:textStyle="bold"
android:typeface="monospace" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="#android:drawable/btn_dropdown" />
<TextView
android:id="#+id/tx5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Address"
android:textColor="#color/black"
android:textStyle="bold"
android:typeface="monospace" />
<EditText
android:id="#+id/ed4"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:hint="Address"
android:minHeight="10sp"
android:background="#android:drawable/editbox_background" />
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="Submit"
android:textColor="#color/black_overlay"
android:background="#drawable/rounded_corner_btn" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Solution 2:
Create .png images and set those images as background of those EditTexts, Spinner and Button using android:background="#drawable/image_name"
For custom font place a font inside asset folder. In code do like this
// Font path
String fontPath = "fonts/Face Your Fears.ttf"; //Face Your Fears.ttf is font name with extension
// text view label
TextView urTxtView = (TextView) findViewById(R.id.urTxtView);
// Loading Font Face
Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
// Applying font
urTxtView.setTypeface(tf);
You can take a look at this tutorial for setting up custom font
First of all try to not set the static height and width. Use wrap_content or match_parent with some margins(Android has a lot of screen sizes and on some devices your view can look very strange).
Create 9.patch file for background (http://developer.android.com/tools/help/draw9patch.html) in your Views. Use selectors for button.
Use shape for your EditTexts etc.(https://stackoverflow.com/a/3264140/3864698)
Customize your Spinner (http://mrbool.com/how-to-customize-spinner-in-android/28286)
I am going through a peculiar problem. I have multiple EditText inside a RelativeLayout which is ultimately inside a ScrollView. My problem is that whenever I edit the second(or third and so on) EditText, it loses focus to the first EditText inside the ScrollView and this first EditText gets the keyboard input.
Here goes the xml layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/particularsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="50dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
<TextView
android:id="#+id/particularsTextView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PARTICULARS"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
/>
<View
android:id="#+id/bar1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/particularsTextView"
/>
<RelativeLayout
android:id="#+id/particularsParentRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bar1"
android:layout_marginTop="10dp"
>
<EditText
android:id="#+id/nameEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_alignLeft="#+id/confirmPasswordEditText"
/>
<TextView
android:id="#+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NAME"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_alignBottom="#+id/nameEditText"
android:layout_marginBottom="15dp"
android:textSize="12sp"
/>
<TextView
android:id="#+id/passwordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PASSWORD"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_alignBottom="#+id/passwordEditText"
android:layout_marginBottom="15dp"
android:textSize="12sp"
/>
<EditText
android:id="#+id/passwordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/nameEditText"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/passwordTextView"
android:layout_alignParentRight="true"
android:nextFocusUp="#+id/passwordEditText"
android:layout_alignLeft="#+id/confirmPasswordEditText"
/>
<TextView
android:id="#+id/confirmPasswordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONFIRM PASSWORD"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_alignBottom="#+id/confirmPasswordEditText"
android:layout_marginBottom="15dp"
android:textSize="12sp"
/>
<EditText
android:id="#+id/confirmPasswordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/passwordEditText"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/confirmPasswordTextView"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
/>
<TextView
android:id="#+id/birthdayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BIRTHDAY"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_alignBottom="#+id/birthdayEditText"
android:layout_marginBottom="15dp"
android:textSize="12sp"
/>
<EditText
android:id="#+id/birthdayEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/confirmPasswordEditText"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/birthdayTextView"
android:layout_alignParentRight="true"
android:layout_alignLeft="#+id/confirmPasswordEditText"
/>
<TextView
android:id="#+id/genderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GENDER"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_marginTop="18dp"
android:layout_below="#+id/birthdayTextView"
android:textSize="12sp"
/>
<TextView
android:id="#+id/contactDetailsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/genderTextView"
android:text="CONTACT DETAILS"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_marginTop="50dp"
/>
<View
android:id="#+id/bar2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/contactDetailsTextView"
/>
<TextView
android:id="#+id/contactNoTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/contactNoEditText"
android:layout_marginBottom="15dp"
android:text="CONTACT NO."
android:textSize="12sp"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
/>
<EditText
android:id="#+id/contactNoEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/bar2"
android:layout_marginTop="15dp"
android:layout_alignParentRight="true"
android:layout_alignLeft="#+id/confirmPasswordEditText"
/>
<TextView
android:id="#+id/emailAddressTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EMAIL AD."
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_alignBottom="#+id/emailAddressEditText"
android:layout_marginBottom="15dp"
android:textSize="12sp"
/>
<EditText
android:id="#+id/emailAddressEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/contactNoEditText"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_alignLeft="#+id/confirmPasswordEditText"
/>
<EditText
android:id="#+id/emailAddressEditText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/emailAddressTextView"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_alignLeft="#+id/confirmPasswordEditText"
/>
<TextView
android:id="#+id/countryTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COUNTRY"
android:textColor="#android:color/darker_gray"
android:textStyle="bold"
android:layout_below="#+id/emailAddressEditText2"
android:layout_marginTop="18dp"
android:textSize="12sp"
/>
<CheckBox
android:id="#+id/termsCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/countryTextView" />
<TextView
android:id="#+id/termsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/termsCheckbox"
android:layout_alignBottom="#+id/termsCheckbox"
android:text="I AGREE TO THE TERMS AND CONDITIONS STATED"
android:textColor="#android:color/darker_gray"
android:layout_alignBaseline="#+id/termsCheckbox"
/>
<Button
android:id="#+id/signupButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/termsTextView"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/signup"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
How to resolve this issue ?
EDIT:
I have attached a screenshot of my problem. I have entered "h" in the passwordEditText but nameEditText gets the value.
mTabHost.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
#Override
public void onViewDetachedFromWindow(View v) {}
#Override
public void onViewAttachedToWindow(View v) {
mTabHost.getViewTreeObserver().removeOnTouchModeChangeListener(mTabHost);
}
});
Add this code in MainActivity.Java #setTabs() function after
mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
this line.
Best of luck.
You can set focus to desired edit text after you make the change: ex.
myEditText3.setFocusableInTouchMode(true);
myEditText3.requestFocus();
It's Working in my device.
I don't know why it's not working in yours, I think in java code, there may be some error.
But you can try,
<RelativeLayout
android:id="#+id/parentLayout"
android:layout_width="match_parent"
android:focusableInTouchMode="true"
android:layout_height="match_parent" >
add 3rd line to your "parentLayout"
I have TextView in RelativeLayout, which works properly:
<TextView
android:id="#+id/tv_client_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:ems="10" />
Now I need to place this TextView inside of ScrollView:
<ScrollView android:id="#+id/sv_client_in"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:fillViewport="true"
>
<TextView
android:id="#+id/tv_client_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
/>
</ScrollView>
After this change layout looks OK (first image), but when keyboard is shown, it is corrupted (second image). How can I fix this?
Full layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv_label_client_host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:ems="10"
android:text="#string/label_host" />
<EditText
android:id="#+id/et_client_host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_host"
android:ems="10"
android:inputType="text"
android:lines="1" />
<TextView
android:id="#+id/tv_label_client_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/et_client_host"
android:ems="10"
android:text="#string/label_port" />
<EditText
android:id="#+id/et_client_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_port"
android:ems="10"
android:inputType="number"
android:lines="1" />
<ScrollView android:id="#+id/sv_client_in"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:fillViewport="true"
>
<TextView
android:id="#+id/tv_client_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
/>
</ScrollView>
<Button
android:id="#+id/btn_client_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/btn_send"
android:onClick="OnBtnSendClick"
/>
<TextView
android:id="#+id/tv_label_client_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_client_send"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:ems="10"
android:text="#string/label_client_out" />
<EditText
android:id="#+id/et_client_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/btn_client_send"
android:ems="10"
android:inputType="text"
android:lines="1" />
<Button
android:id="#+id/btn_client_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/et_client_port"
android:text="#string/btn_client_clear"
android:onClick="OnBtnClearClick"
/>
<Button
android:id="#+id/btn_client_disconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/et_client_port"
android:text="#string/btn_client_disconnect"
android:onClick="OnBtnDisconnectClick"
/>
<Button
android:id="#+id/btn_client_connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_client_port"
android:layout_toLeftOf="#+id/btn_client_disconnect"
android:text="#string/btn_client_connect"
android:onClick="OnBtnConnectClick"
/>
<TextView
android:id="#+id/tv_label_client_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/btn_client_connect"
android:ems="10"
android:text="#string/label_client_in"
/>
</RelativeLayout>
This happens mainly because of the views aligning to bottom. You have aligned them to bottom, so when the keyboard pops up the bottom changes hence the Views associated with it.
Try checking your xml file.
The problem is solved by using LinearLayout.