android. Autofocused textview on activity startup - android

I have a activity, which view have a several EditText components.
When activity starts, the first of EditTexts became focused and keyboard appears. I would like to avoid this 'feature' ( I mean I want that there will be no popup keyboard after activity started)

Create a LinearLayout (I dunno if other kinds of Layout's will work). Set the attributes android:focusable="true" and android:focusableInTouchMode="true".
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true" android:focusableInTouchMode="true"
android:layout_width="0px" android:layout_height="0px"/>
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="#+id/text"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:nextFocusUp="#+id/text" android:nextFocusLeft="#+id/text"/>

Try adding
android:windowSoftInputMode="adjustPan"
to the activity element in your manifest.

Related

How to move focus from RowsSupportFragment's row to next layout component?

I am using Android Leanback library for creating TV application. I have a layout which inflates Fragment (which is RowsSupportFragment) and below that there is button. So, when I scroll down to list of items in RowsSupportFragment after reaching to last item focus doesn't goes to button.
I already have tried setting focusable(true), nextFocusDown(buttonId) etc.
I can see that RowsSupportFragment uses VerticalGridView internally to inflate list of items.
Do anybody has any idea about it?
here is my layout:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/listviewFragmentId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:nextFocusDown="#id/nextButtonId"
android:nextFocusForward="#id/nextButtonId"
layout_constraintBottom_toTopOf="#id/nextButtonId"/>
<Button
android:id="#+id/nextButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:focusable="true"
android:text="Hello Next"/>
<// other items>
</android.support.constraint.ConstraintLayout>
Note:
Focus works correctly if I left/right align button.
In My case this was work when i need focus on the any views
view.requestFocus();
In My case,i need focus on the any views on right outside of RowSupportFragment item so Working around with focusOutEnd,focusOutFront and other focus features in the Leanback Style solved my solution.
like for requesting the focus to outside Button widget from RowSupportFragment, setting <item name="focusOutEnd">true</item> in style worked for me.

Android intent for software

Thata code insted
keyboardview or one of its extended class. You have not shared your RelativeLayout but i think The exception may be because of some problem with your RelativeLayout.
You can put a button to the right of Keyboard like this(res/layout/input.xml):
< com.android.example.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:keyBackground="#drawable/kb_exagon_base"
You can use any View/ViewGroup as a keyboard layout, Infact you can even set the keyboard layout to a view which is not an instance of keyboardview or one of its extended class. You have not shared your RelativeLayout but i think The exception may be because of some problem with your RelativeLayout.
You can put a button to the right of Keyboard like this(res/layout/input.xml):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboardLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/ic_launcher"/>
And then return an instance of this layout from OnCreateInputView.
Update:
The statement mInputView = (KeyboardView) getLayoutInflater().inflate( R.layout.input, null); in your below comment will throw ClassCastException as the inflated view is not an instance of KeyboardView.
you need to change it like this:
public View onCreateInputView() {
mInputView = (View)getLayoutInflater().inflate( R.layout.input, null);
mKeyboardView = (KeyboardView)mInputView.findViewById(R.id.keyboardView);
mKeyboardView.setOnKeyboardActionListener(this);
mKeyboardView.setKeyboard(mQwertyKeyboard);
return mInputView;
}
the keyboard pops up from the bottom and you can define the behavior in your manifest using the following line android:windowSoftInputMode:
<activity
android:name=".NAME"
android:label="#string/appName"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#style/Theme.HOLOorAnyThemeYouWant"
android:windowSoftInputMode="stateAlwaysHidden" >
from documentation :
android:windowSoftInputMode
How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:
The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
The adjustment made to the activity's main window — whether it is resized smaller to make room for the soft keyboard or whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard.

Status bar always on screen

Good day (or evening, or night)
I'm developing an app for android and I'm very curious about one thing. I have an activity, where user chats with another, like "im" chat. There are an EditText on the bottom and some kind of actionbar on the top. What I need is when user enters a message and the software keyboard is on screen, my activity should move up, but the actionbar should still be "glued" to the top of the screen, because it has some valuable controls on it.
Again, that's not an ActionBar, but just a 48dp height layout in a parent vertical linear layout. So I need to know is there an easy way to prevent it from moving to the top, when the layout moves off the screen.
I tried to put everything in a FrameLayout and put this bar on top of it, but on keyboard opens it goes off the screen too...
On you Activity at AndroidManifest you should put this: android:windowSoftInputMode="adjustResize"
Use something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.myapp.MyActionBar
android:layout_width="match_parent"
android:layout_height="48dp"/>
<LinearLayout
android:id="#+id/mylayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1dp"/>
<!-- Add your edittext and button -->
</LinearLayout>
This will make sure the actionbar and edittext + button are allways on screen, and the mylayout takes up the rest of the screen. When your keyboard is shown, the mylayout will shrink.
Try adding android:windowSoftInputMode="adjustResize" to your activity in the manifest. This tells Android to completely resize your layout when the keyboard comes up, rather than pan it. Note that if there isn't enough room for the entire layout this still won't work. But you ought to be able to make it work if your top level layout is a RelativeLayout, with the edit text set to align bottom, the top bar to align top, and the middle section to fill_parent and be above the edit text and below the bar.
use a RelativeLayout as your base Layout and add android:layout_alignParentTop="true" to your action bar to keep it up
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/action_bar_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true" >
</LinearLayout>
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>

Focus in GridView layout

In my Android app, I have a GridView layout with a set of Buttons. The problem is, that I can't set properly the focus (I mean cursor, controlled with joystick on the Android device) on the buttons. I can describe my problem with a picture:
I set the Buttons to the GridView dynamically in the code in BaseAdapter using LayoutInflater. In the code, I set button's text, image (CompoundDrawable) and background color, because my buttons works like a checkboxes (blue background means checked).
It seems like the program is focusing the grid field and not the button itself. I mean something like cell of table and not the button in table. Because the focus color is default (green) however I set the blue color in selector. Focus press also doesn't work. And the focus is evidently behind the button, out of button's bounds. Can somebody help me with this trouble please? Code of my XML layouts:
main.xml:
...
<GridView
android:id="#+id/channels"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dip"
android:verticalSpacing="10dip"
android:horizontalSpacing="10dip"
android:numColumns="auto_fit"
android:columnWidth="60dip"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#color/container_main">
</GridView>
...
channel.xml:
<Button
android:id="#+id/channel"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:background="#color/willBeSetInAdapter" <!-- white/blue/darkblue focus background -->
android:drawableTop="#drawable/willBeSetInAdapter" <!-- icon -->
android:drawablePadding="0dip"
android:text="WillBeSetInAdapter" <!-- label text -->
android:textColor="#color/text_container_main"
android:textSize="12sp"
android:focusable="true"
android:focusableInTouchMode="false">
</Button>
I tried to set focus parametres in Button and also in GridView and tried a lot of things, but unfortunately it still doesn't work :(
Setting android:descendantFocusability="afterDescendants" for GridView solved my problem. Because program focused the grid field and not the button itself. Using descendantFocusability parameter I forbid to focus grid field and allow only to focus the buttons.
Have you tried setting android:drawSelectorOnTop="true" for your GridView?

How does Android determine whether to move the layout up when showing the softkeyboard?

How does Android determine whether to move the layout up when showing the softkeyboard?
Note: I am aware that the activity property android:windowSoftInputMode="adjustResize|adjustResize|adjustUnspecified"
exists, as described here http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
, but in my case it doesn't seem to have any effect. This is my problem:
I have two activities, pretty much the same layout, but the first one is using a ListView that holds a list of buttons. The second activity holds a scrollview with buttons.
The rest is the same, same number of buttons, same height of elements, etc.
Now, when I press the search button to open the search input bar, in my first activity, the entire layouts gets moved up.
While on the second activity, the layout is not being moved up but the softkeyboard just displays on top of it. This is actually how I want it to behave. How can I achieve the same with my activity that's using the ListView?
In my manifest, initially I didn't specify any android:windowSoftInputMode attribute, but even if I do, it doesn't make any difference; I tried all three values (adjustPan, adjustResize, adjustUndefined, without any difference).
This is my layout:
1) http://pastebin.com/5zzVxjbK
2) http://pastebin.com/KFtPuHvP
Interestingly though: when I set my ListView visibility in my layout 1 (left) to View.INVISIBLE, then the layout doesn not get moved up!
I can achieve this with a RelativeLayout and setting android:windowSoftInputMode="adjustPan" like so:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<include android:id="#+id/Header" layout="#layout/header"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<ListView android:id="#+id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="#id/Header"
android:layout_above="#+id/Footer" />
<include android:id="#id/Footer" layout="#layout/footer"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
You may be able to achive this by setting the footer gravity (or layout_gravity) to "bottom", if you want to keep the LinearLayout, but I am not sure.

Categories

Resources