I have a recycler-view with a sample background in my activity but I'm stuck in an error. Whenever keyboard popups in the activity, the background of recycler-view gets shrink. How to avoid this thing. Means how to stop it from being shrinking ? Here are the images attached below.
normal Image
shrinked background
XML Code:
<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="#drawable/splash_bg"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/editText" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="5dp"
android:background="#fff"
android:hint="Your text here"
android:inputType="text"
android:padding="12dp"
android:textSize="24sp" />
</RelativeLayout>
In the tag of the recyclerview container activity declared in manifest add
android:windowSoftInputMode="stateHidden|adjustNothing"
like
<activity
android:name=".YourActivityName"
android:windowSoftInputMode="stateHidden|adjustNothing" />
add the image to your background of layout, not in recyclerview. And also recyclerview's item should have no background color except its necessary to widgets.
Set attribute android:windowSoftInputMode to be "adjustPan" in your AndroidManifest.xml under your activity:
<activity
android:name=".YourActivityName"
android:windowSoftInputMode="adjustPan" />
Related
I want to make a chat screen which has an EditText and a Button at the bottom (wrapped in a LinearLayout), and a ScrollView for the messages at the top. The problem is that when the user taps the EditText and the keyboard opens, the ScrollView will go off screen as a result of moving up. I would like to move the Layout (with the EditBox and the Button) above the keyboard and the ScrollView to be resized to fit the screen. The problem is shown on the pictures below:
As you can see, the line that writes "Chat" (left image) has disappeared in the right image.
I use this XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:padding="15sp"
android:orientation="vertical"
android:background="#ccdcf7"
tools:context="com.orionz.sockettest.ChatActivity">
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15"
android:isScrollContainer="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/chatBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Chat\n"
android:textColor="#000000"
android:textIsSelectable="true"
android:textSize="22dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="horizontal">
<EditText
android:id="#+id/msgInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:ems="10"
android:hint="Message..."
android:inputType="text" />
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:background="#drawable/mybutton"
android:padding="5sp"
android:text="Send"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
I have seen many answers such as setting the android:windowSoftInputMode but none has worked. I use Android Studio. Any help would be appreciated.
Try to replace the ScrollView with a ListView like this :
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
store all the messages in an ArrayList, and set an adapter to the ListView you made :
ListView listView=(ListView) findViewById(R.id.list_view);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ArrayList);
listView.setAdapter(adapter);
Finally, add a listenner on your Button writing these lines :
EditText editText= (EditText) findViewById(R.id.msgInput);
ArrayList.add(editText.getText().toString());
adapter.notifyDataSetChanged();
Finally, I found what was wrong in my case.
The theme was full screen. In the style of the activity I had this line that caused the problem:
<item name="android:windowFullscreen">true</item>
In the java code, I gave a command to open the keyboard on the start of the activity:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
which was also part of the problem
After adding the adjustResize property to the activity in the manifest, everything worked fine:
android:windowSoftInputMode="adjustResize"
Wrap Scrollview to the whole layout.
i.e place editText and button inside Scrollview and set scrollView Height to android:layout_height="match_parent"
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"
>
I have a simple android layout and code, but the keyboard always overlap my AutoCompleteTextView when I click it.
Note : The AutoCompleteTextView when inside ScrollView.
Note : platform is 6.0.1
package com.example.jason_wu.search;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AutoCompleteTextView;
public class Main2Activity extends AppCompatActivity {
private AutoCompleteTextView mAtv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
mAtv = (AutoCompleteTextView) findViewById(R.id.location_auto_complete);
//issue 1
//mAtv.setBackground(getDrawable(R.drawable.search_input_focus));
//issue 2
mAtv.setHeight(300);
}
}
and my AndroidManifest.xml here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jason_wu.search">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.jason_wu.search.Main2Activity"
android:windowSoftInputMode="adjustPan"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="800dp"
android:text="Large Text"
android:id="#+id/textView"/>
<AutoCompleteTextView
android:id="#+id/location_auto_complete"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView"
android:background="#color/transparent"
android:dropDownAnchor="#+id/location_auto_complete"
android:dropDownHeight="wrap_content"
android:dropDownVerticalOffset="1dip"
android:fontFamily="sans-serif-light"
android:hint="#string/new_notification_location_hint"
android:imeOptions="actionSearch"
android:inputType="textUri"
android:dropDownSelector="#color/location_bg_select"
android:popupBackground="#color/location_bg_notselect"
android:singleLine="true"
android:textColor="#FFFFFF"
android:alpha="0.2"
android:textColorHint="#999999"
android:textCursorDrawable="#null"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView2"
android:layout_below="#+id/location_auto_complete" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
See
try this attribute to the activity in the AndroidManifest.xml
android:windowSoftInputMode="stateHidden|adjustPan"
it should look something like this.
<activity
android:name="com.myexample.TestActivity"
android:label="#string/login_screen"
android:screenOrientation="portrait" // well you can change the orientation if you want
android:windowSoftInputMode="stateHidden|adjustPan" />
the attribute you want to play with is this windowSoftInputMode try different values as you may require different output after certain time.
adjustPan
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
adjustResize
The activity's main window is always resized to make room for the soft keyboard on screen.
stateHidden
The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
you can find more details on activity-element documentation
Update
I have written something that might help you, layout is available on the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="activities.list.first.TestLayoutActivity">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:orientation="vertical">
<AutoCompleteTextView
android:id="#+id/TestLayoutActivity_autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:completionThreshold="1"
android:drawableLeft="#android:drawable/ic_menu_search"
android:text="" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
AndroidManifest.xml
<activity
android:name="activities.list.first.TestLayoutActivity"
android:label="#string/title_activity_test_layout"
android:windowSoftInputMode="stateHidden|adjustPan"
/>
Code is on the code
String[] list = {"match1", "match2", "match3",
"match12", "match11", "match8", "match7", "match4",
"match13", "match10", "match9", "match6", "match5",};
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.TestLayoutActivity_autoCompleteTextView);
ArrayAdapter<String> adapter
= new ArrayAdapter<String>(getApplicationContext(), R.layout.simple_list_item_1, list);
autoCompleteTextView.setAdapter(adapter);
Before
After
[
Try limiting the dropdown items to show
One way is you can Limit the dropdown items to show. But there's no such proper way of it to show number of maximumSuggestions option, But the trick you can apply is Get the height of one of the rows and multiply it (number of rows to show) times and use setDropDownHeight() to set its height.
There is a method setDropDownHeight of AutoCompleteTextView class. You can see them and use.
If you are confused or not sure of height of suggestions items you can customize this. Have a look how to set custom height.
The keyboard behavior is that scroll the view to close the bottom of text area.
Finally, we have to use android:gravity="bottom" attribute to solve UI issue, but we need to consider the UX, ex: Hint.
So, The solution is to listen onClick() and For keyboard issue, we have to use dynamic method to set the gravity.
I am trying to create a login screen. I have used ScrollView to hold input fields. I have following xml:
<RelativeLayout ... >
<RelativeLayout
android:id="#+id/top_menu" ... >
<ImageButton ... />
<com.neopixl.pixlui.components.textview.TextView... />
</RelativeLayout>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/top_menu"
android:overScrollMode="always">
<LinearLayout
android:id="#+id/login_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<com.neopixl.pixlui.components.edittext.EditText
android:id="#+id/user_name_email"
android:layout_width="match_parent"
android:layout_height="#dimen/input_height_size"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/edit_text_strock"
android:hint="#string/user_Name_Email_EditText"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:textColor="#color/White"
android:textColorHint="#color/White"
android:textSize="#dimen/register_input_text_size"
pixlui:typeface="MuseoSans.otf"/>
<com.neopixl.pixlui.components.edittext.EditText.... />
<com.neopixl.pixlui.components.button.Button... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.textview.TextView... />
<com.neopixl.pixlui.components.button.Button... />
</LinearLayout>
</ScrollView>
</RelativeLayout>
You can see full xml here.
When I click on EditText user_name_email, it goes off the screen.
Before click:
After click:
I have tried scrollTo(x, y) and smootScrollTo(x, y) bu they didn't work.
How can I fix it?
UPDATE:
adjustPan works but I want it to work with adjustResize.
Is it possible?
Use the following line in the manifest file, for the activity you need the change.
android:windowSoftInputMode="adjustPan"
Use it as shown below:
<activity
android:name=".ActivityName"
android:label="title_for_activity"
android:windowSoftInputMode="adjustPan" >
</activity>
Hope this helps.
add this to manifest file:
android:windowSoftInputMode="adjustPan"
in the targeted activity tag.
Any idea why the following layout is not scrollable? I have a RelativeLayout in a ScrollView. The Views fit on the screen. however they are covered whenever the keyboard pops up. I want to make the screen scrollable when the keyboard pops up, because it covers the Login and password EditBoxes so it is har to see what someone is typing
<?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:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.alarm.alarmmobile.android.view.RobotoLightTextView
android:id="#+id/passcode_login_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:text="#string/passcode_login_body"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/passcode_login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/passcode_login_text"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:hint="#string/login_textview_username"
android:singleLine="true" />
<EditText
android:id="#+id/passcode_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/passcode_login_username"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:hint="#string/login_textview_password"
android:inputType="textPassword"
android:singleLine="true" />
<com.alarm.alarmmobile.android.view.RobotoLightButton
android:id="#+id/passcode_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/passcode_login_password"
android:layout_marginRight="16dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="#string/login_button_login" />
</RelativeLayout>
</ScrollView>
On the activity or fragment class of this layout you have to call this:
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Include this in your Manifest:
<activity android:name="..." // your activity here
....
android:windowSoftInputMode="adjustResize|adjustPan">
/>
NOTE: Not sure if adding adjustPan will cause the problem to come up again or not.
If everything can fit on the screen, the ScrollView will not be able to scroll anywhere. If there is a component that is not fully visible then the scroll should be available to see the rest of the component. Without being able to see what the problem is it's hard to find the exact solution.