I have a chat fragment with a listview and a edittext and i wanna when the user rotate the device, if the keyboard was shown, it still showing.
But on my fragment, if the user rotate from landscape to portrait and the keyboard is open, it reapear open. But from portrait to landscape, it closes on rotation.
I have no idea what could be and how could i save the keyboard state to recover it.
Thanks in advance.
<?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"
android:gravity="bottom"
android:orientation="vertical" >
<com.example.irclient2.adapter.MyEditText
android:id="#+id/chatinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:imeOptions="actionSend|flagNoExtractUi"
android:inputType="textCapSentences" />
<ListView
android:id="#+id/chatlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/chatinput"
android:background="#drawable/fundo_chat"
android:divider="#android:color/transparent"
android:dividerHeight="1.0sp"
android:padding="5dp"
android:scrollingCache="false"
android:smoothScrollbar="true"
android:transcriptMode="normal" >
</ListView>
Try removing/commenting any code you have in your fragment and activity that deals with handling focus and/or the keyboard (to isolate the problem) and try the solution to this question:
Keyboard issues arising on orientation change
Related
I have an Activity where i want the view to be on left side of the device(opposite side of volume/power button) in all cases.
I have no problem doing this in portrait and landscape orientation for the Activity, but when it goes to reverse-landscape and reverse-portrait the view will go to the right side of the device(volume/power button side).
Is it possible to allow screen orientation changes but block reverse-orientations?
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<CustomView
android:layout_width="150dp"
android:layout_height="wrap_content"
>
</CustomView>
<include
layout="#layout/some_layout"
>
</include>
</LinearLayout>
activity_main.xml(land):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<CustomView
android:layout_width="wrap_content"
android:layout_height="150dp">
</CustomView>
<include layout="#layout/some_Other_layout" />
</LinearLayout>
I have tried orientationListener, whenever it goes to reverse-landscape i try to set orientation to landscape and then release the orientation by setting unspecified but that did not work as screen was getting locked and further changes in orientation where not getting detected.
Any ideas on how this can be solved?
You can prevent the reverse landscape as below Kotlin code
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
You can use below Java code
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
I have a view(Let's say it is MyFramLayout) extends FrameLayout, I can not get this FrameLayout get focus when press key(I am working in TV platform).
the layout is something like this:
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.roger.MyFrameLayout
android:id="#android:id/my_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true" />
</LinearLayout>
Anyway to fix the problem?
Whenever you want your custom layout to get focus you will have to call
boolean b = yourLayout.requestFocus();
This will return a whether focus is gained or not.
I've been trying to solve it for a few days and have been looking for an answer for this.
Does anybody know why this happens?
Closed keyboard vs open keyboard:
My MainActivity.xml (where the root for fragment transaction)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="fill_parent" />
</LinearLayout>
I have another Fragment with a ScrollView and without any type of input, so I don't use the keyboard there and it works fine. Please help me.
In my android app, in my profile edit page, when I start the activity, the first edittext field is focused (blinking cursor), and the keyboard gets displayed.
How can I keep it being focused on startup (blinking cursor) but prevent the keyboard from showing up? If that is not possible, then just not focus the edittext on startup.
Thanks.
<EditText
android:id="#+id/textinput_firstname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="test" />
Just add this line of code in your onCreate(...) method
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
This is probably happening for EditText for most users, all you have to do is, just go to the layout file and set the layout's view groups attributes as follows:
android:focusable="true"
android:focusableInTouchMode="true"
For Example.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:focusable="true"
android:focusableInTouchMode="true">
<EditText
android:layout_width="match_parent"
android:layout_height="41dp"
/>
</LinearLayout>
Note: you have to set the attributes for the first view in the layout
no matter what it is This will set the default focus to false;
I read a lot of topic related to this item but none of them solved my problem. Here is the layout of my chat screen:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/chatPage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/speech_bg" >
<include
android:id="#+id/chatHeader"
layout="#layout/header_chat" />
<RelativeLayout
android:id="#+id/chatView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/chatHeader" >
<RelativeLayout
android:id="#+id/chatBottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/speech_text_bg"
android:padding="5dp" >
<RelativeLayout
android:id="#+id/chatSendButton"
android:layout_width="#dimen/chatSendButtonWidth"
android:layout_height="#dimen/chatSendButtonHeight"
android:layout_alignBottom="#+id/chatEditText"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:background="#drawable/chat_send_btn_selector"
android:onClick="ChatSendButtonClick" >
<com.xxx.Utils.MyTextView
xmlns:customtext="http://schemas.custom.com/android/customtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/chatSendText"
android:textColor="#ffffff"
android:textSize="#dimen/chatSendTextSize" />
</RelativeLayout>
<EditText
android:id="#+id/chatEditText"
android:layout_width="match_parent"
android:layout_height="#dimen/editTextHeight"
android:layout_toLeftOf="#+id/chatSendButton"
android:background="#drawable/edit_text"
android:inputType="textMultiLine"
android:maxLines="5" />
</RelativeLayout>
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:pulltorefresh="http://schemas.custom.com/android/pulltorefresh"
android:id="#+id/chatList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/chatBottomView"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:fadingEdge="none"
android:fadingEdgeLength="0px"
android:listSelector="#00000000"
pulltorefresh:type="chat" />
</RelativeLayout>
I added AdjustPan option to the AndroidManifest.xml:
<activity
android:name=".ui.ChatActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan" >
</activity>
AdjustResize doesn't work in my implementation since there's not a scrollview in it, I guess.
What is the best way to resize/adjust my chat page when soft keyboard opens? As far as I see, there's no implementation for listening the keyboard in Android either. I only saw some samples related with global layoutlistener to understand the keyboard position but it didn't work well for me.
Why does adjustpan option hides my actionbar instead of only chat screen?
Added to pulltorefreshlistview in chat.xml layout:
android:transcriptMode="alwaysScroll"
It solved everything. If the chat list view is scrollable in any kind of conditions, it doesn't need to listen the keyboard event to scroll the list view manually.
Hope it helps to anyone other than me either..