I have a Text View below an EditText.
When I enter data into the EditText, the TextView moves up, so that it is still visible.
I mean I enter data, the keyboard comes up and the TextView moves also up.
But I don't want that, I want the TextView to stay where it is.
I am using a ConstraintLayout and I can't set the constraints tighter, because the TextView will be filled with data if I hit a button.
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:layout_marginTop="50dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:hint="#string/hint1"
android:importantForAutofill="no"/>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constrainedHeight="true">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/emptyString" />
</ScrollView>
what I think is, you have put the text view in the in the scroll view that's why it is behaving in that way.
I found the solution, it was adding this line in the starting activity tag:
android:windowSoftInputMode="adjustPan"
Like this:
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Now when the keyboard appears the TextView is not moving anymore.
It is overlaid by the keyboard, but I like to have it that way rather than having moving views.
Related
I have a login screen with an ImageView"pinned" (using layout constraints) to the bottom of my Parent ConstraintLayout. I have tried just about everything I can find on SE to get my image to stay put when the soft keyboard pops up, but to no avail. I have to wonder if that's because I pinned the image to the bottom of the view?
XML for the ImageView
<ImageView
android:id="#+id/imageView4"
android:layout_width="152dp"
android:layout_height="66dp"
android:layout_alignParentBottom="true"
android:layout_marginStart="24dp"
android:foregroundGravity="bottom"
android:gravity="bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/half_frog" />
Manifest
<activity
android:name=".LoginScreen"
android:windowSoftInputMode="adjustNothing"
/>
In my layout file, I have an EditText, under scrollbar, User can write till 1000 character. I gave Fixed Height to it, when user try to enter text( more then 500 character), It slightly start scrolling to top, and after some time edit text become disappear. I can pulled down to it, but when ever it get focus again, it again scroll to top and disappear. There are lots of View In my screen so Page is quite longer.
Menifest File:
<activity android:name="ActivityName"
android:exported="true"
android:hardwareAccelerated="true"
android:label="#string/title_activity_manage_job"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize|stateHidden" />
My Layout
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
//Other View are availble on top and bottom of edit textl̥
<EditText
android:id="#+id/edt_profileSummary"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/squre_edittext"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:overScrollMode="always"
android:inputType="textMultiLine"
android:gravity="top"
android:maxLength="1000"
android:maxLines="25"
android:padding="10dip"
android:textColor="#android:color/black"
android:textCursorDrawable="#drawable/color_cursor"
android:textSize="#dimen/small_text_size" />
</android.support.v4.widget.NestedScrollView>
Please help me, If you understand my problem.
I am using EditText but when Activity is started my EditText is already focused. I want to remove focus and also make it editable on click.
Here is the code of my edittext.
<EditText
android:id="#+id/et_HotelLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:drawableLeft="#drawable/ic_edit_location_black_24dp"
android:drawablePadding="8dp"/>
You can create dummy layout as below which you should keep exactly above your EditText and then use nextFocusUp and nextFocusLeft as shown.
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:id="#+id/et"
android:drawablePadding="8dp"
android:nextFocusUp="#id/et"
android:nextFocusLeft="#id/et"
app:met_floatingLabel="normal" />
Add the following two properties in parent Layout of the Edit text
android:focusable="true"
android:focusableInTouchMode="true"
if your edit text is inside linear layout you can do like this
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/et_HotelLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:drawableLeft="#drawable/ic_edit_location_black_24dp"
android:drawablePadding="8dp"/>
</LinearLayout>
This question has already been responded here
Try this also -
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Otherwise, declare in your manifest file's activity -
<application android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".Main"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden"
>
my scroll view contains a linear layout which further contains some of the edit text fields. now when I click on a edit text field at the bottom one then soft keyboard appears, but my problem is that it covers that edit textfield. this is my activity declared in android manifest file:
<activity
android:name="me.example.scrollview.LoginActivity"
android:label="#string/title_activity_login"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" >
</activity>
and here is my layout.xml file for this activity.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
tools:context=".LoginActivity" >
<ScrollView
android:id="#+id/login_sv_login_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:background="#android:color/transparent" >
<LinearLayout
android:id="#+id/login_ll_container"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:orientation="vertical" >
<EditText
android:id="#+id/txt_username"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/rounded_edittext"
android:ems="10"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/txt_phone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_edittext"
android:ems="10"
android:inputType="phone"
android:maxLines="1"
android:singleLine="true" />
<EditText
android:id="#+id/txt_password"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_edittext"
android:ems="10"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
<Button
android:id="#+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:background="#drawable/ic_login"
android:text="" />
</LinearLayout>
</ScrollView>
Now Please help me as I am very new to android programming. I am unable to fix this issue and can't find a way to scroll my scroll view without resizing my main window.I just want my scroll view to make scrolling when soft keyboard appears.Thanx in advance.
Both previously pointed out solutions can work. But there might still be a problem if the edittext is at the bottom of the ListView where it would still be covered by the onscreen keyboard. Not sure if a scrollview can be scrolled to a point where there is no more content.
What i've seen is that you might use two contradicting flags in your manifest:
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>
adjustResize and adjustPan can imho NOT be combined. Try how it looks with only adjustResize. This should avoid that the keyboard covers anything of your view.
You can try:
ScrollView scroll = (ScrollView)findViewById(R.id.scrollview);
scroll.scrollTo(0, sv.getBottom());
or
scroll.scrollTo(5, 10);
You can use YOURSCROLLVIEW.scrollTo(int x, int y) or YOURSCROLLVIEW.smoothScrollTo(int x, int y) to move the scroll view to the appropriate coordinates so that the edit text box and keyboard are both shown.
More information about these functions and other scrollview functions can be found on the android developer reference page.
I have 2 classes, FirstActivity and SecondActivity.
First Activity
Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
startActivity(intent);
Is it possible for SecondActivity to overlay on FirstActivity? ie. FirstActivity gets dimmed, SecondActivity gets displayed on top of FirstActivity.
If it is not possible for 2 different activities, is it possible to do an overlay for 2 views in the same activity? I hope using dialog is not the only option.
I suggest you set your second activity up as a dialog -- which will dim the background. Here is a tutorial that could be helpful:
http://developer.android.com/guide/topics/ui/dialogs.html
http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application
Or you can simply set the theme in the manifest as a dialog for your SecondActivity.
If you don't want to do a dialog, you can overlay views using a relative layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="some content"
android:textSize="70dp"/>
</LinearLayout>
<LinearLayout android:id="#+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99000000"
android:clickable="true"
android:visibility="gone">
<EditText android:id="#+id/edittext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="50dp" />
</LinearLayout>
</RelativeLayout>
The first LinearLayout (id/content) is your base layout where your normal content would go.
The second LinearLayout (id/overlay) is your overlay layout which you'd want to show over top of the base layout. The background color will give give you that faded out background, and you can add whatever you want to that layout to make your overlay. To show the overlay, just change its visibility from gone to visible.
In manifest file declare the secondactivity activity like this. android:theme="#android:style/Theme.Dialog".then simply call the secondactivity from firstactivity from your code.
<activity
android:name=".FirstActivity"
android:label="#string/title_activity_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="#string/title_activity_second"
android:theme="#android:style/Theme.Dialog"
>
<intent-filter>
<action android:name="transparent.text.SECONDACTIVITY"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Second Activity xml file.you can design as your wish but for reference i have posted this.the key concept is in manifestfile (ie) how to define your secondactivity in manifest
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="192dp"
android:background="#aabbcc"
android:text="Sybrant has provided Takoma with a great team which helped us from the beginning to the final stage of our product, to our fullest satisfaction. We have been able to deliver a high quality of eLearning products to our corporate customers like Nissan with Sybrant’s support”"
tools:context=".FirstActivity" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="43dp"
android:layout_marginLeft="80dp"
android:text="Button" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button1"
android:layout_below="#+id/textView1"
android:layout_marginRight="42dp"
android:layout_marginTop="80dp"
android:text="TextView" />
</RelativeLayout>
1-Take a screenshot of the first activity.
2-(Optional) Darken, tint or blur the screenshot.
3-Then call the second activity and use the first activity screenshot as background for the second activity.