I am developing android custom keyboard and faced this problem. I am using candidates view to show suggestions. But in some cases when I am trying to use keyboard in applications Layout is going under status bar.
I have attached two images of problem. In both screenshots with red rectangle I have marked problem and with green rectangle Keyboard layout.
I have done research about this and find that it can be caused if Candidate view is not created in right way, but I have implemented candidate view as shown in examples.This is an Image from Facebook messenger
In this image keyboard is overlapping messengers edit text layout too.
Here are my code snippets from SoftKeyboard where i am creating candidates view.`
#Override public View onCreateCandidatesView() {
mCandidateView = new CandidateView(this);
mCandidateView.setService(this);
mCandidateView.setOnTranslitModeChangedListener(this);
return mCandidateView;
}`
my keyboard xml file
<?xml version="1.0" encoding="utf-8"?>
<com.innorise.kitkeysarmenian.LatinKeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="50dp"
android:keyTextSize="18dp"
android:keyTextColor="#000"
android:background="#color/keyboardBackground"
android:keyPreviewLayout="#layout/preview"
android:popupLayout="#layout/keyboard_popup_layout"
android:drawingCacheQuality="high">
and here is my candidates view xml file`
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:padding="5dp"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/candidatesList"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/candidateSwitch"/>
<TextView
android:textSize="18sp"
android:visibility="gone"
android:text="Translit is off."
android:gravity="center"
android:id="#+id/translitModeisOff"
android:layout_toLeftOf="#+id/candidateSwitch"
android:layout_width="match_parent"
android:layout_height="30dp" />
<com.rm.rmswitch.RMSwitch
android:id="#+id/candidateSwitch"
app:switchDesign="slim"
app:switchBkgCheckedColor="#4ed736"
app:switchBkgNotCheckedColor="#cccccc"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
app:switchToggleCheckedColor="#aca2a2"
app:switchToggleNotCheckedColor="#aca2a2"
android:layout_width="50dp"
android:layout_height="35dp"/>
</RelativeLayout>
add this to your manifest :
<activity
android:name="activity.name"
android:windowSoftInputMode="adjustPan|adjustResize"/>
Related
Edit: everything is fine with the code, Android Studio is not deploying changes to app version 4.1.3
Im trying to change the background color of view(Relative layout and rootView) at runtime
but its not working at all here is the code
rootview = findViewById(R.id.rootView)
rootview.setBackgroundColor(resources.getColor(R.color.backgroundColor2))
Layout code/file, I'm using relativeLayout as the main layout here which is overridden by another view completely
<?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:id="#+id/rootView"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="#+id/banner_container"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
<at.markushi.ui.CircleButton
android:id="#+id/button"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerInParent="true"
android:src="#drawable/ic_launcher_foreground"
app:cb_color="#color/mainButtonColor1"
app:cb_pressedRingWidth="8dip" />
<at.markushi.ui.CircleButton
android:layout_width="64dp"
android:elevation="8dp"
android:layout_height="64dp"
android:src="#drawable/ic_launcher_foreground"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
app:cb_color="#B71C1C"
app:cb_pressedRingWidth="8dip" />
</RelativeLayout>
If I set the background in XML it works fine
I think because you are using a Relative layout. So maybe, your relative layout is overridden or covered by another View (like view 2 is covered by view 1 and view 3 ). And when you change the background of view 2, this function worked but you don't see it because it is being covered by view 1 and view 3. You should try Liner Layout to replay.
I have gone through various answers but was unable to move my view up when keyboard is visible. I have a edittext in recyclerview on whose focus keyboard is visible.I want the tv_character_limit text to be moved up when keyboard is visible. I need the character limit text to be shown elevated with a z-index. I have set the windowSoftInputMode to adjustResize for the activity and for the fragment in view pager i have added the java code:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Thank you for help.Below is my layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rel_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/pink">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_post" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_status"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<TextView
android:id="#+id/tv_character_limit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="10dp"
android:layout_marginBottom="30dp"
android:text="#string/character_limit"
android:textColor="#color/tap_to_type"
android:textSize="15dp" />
</FrameLayout>
use,
android:windowSoftInputMode="adjustPan"
in the manifest file for your activity.
ex :
<activity
android:name=".View.Activity.yourActivity"
android:windowSoftInputMode="adjustPan"/>
Instead of FrameLayout, use RelativeLayout and when your EditText gets focus, just change the position of TextView by calling the RelativeLayout class method similar to layout_above.
So I have an xml that consists of a linear layout containing a Button and a TextView like this:
<?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="100dp"
android:orientation="vertical">
<Button
android:id="#+id/btnCell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:paddingLeft="40dp"
android:text="Button"
android:textColor="#color/blueText" />
<View
android:height="wrap_content"
android:width="wrap_content"
android:background="#drawable/Test"/>
</LinearLayout>
And I want to use this same layout inside other layouts in a different xml. I need the same button at every time, so I reuse it by including it in the two layouts (both layouts are in the same xml, but ones is hidden):
First one
<?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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/image"
/>
<include layout="#layout/buttonLayout"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Second One:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/image"
/>
<include layout="#layout/buttonLayout"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
So I show the first layout and hide the second one at the beginning of the app , as the user moves within the interface, the layouts exchange so that the other one is shown and the first one hidden.
The thing is that I declare the Button in my java activity class like this:
btnCell = (Button) thirdView.findViewById(R.id.btnCell);
btnCell.setOnClickListener(this);
And implemented the listener.
#Override
public void onClick(View v) {
if (v == btnCell) {
System.out.println("entered if");
}
System.out.println("entered function");
}
The problem is that when I click the button when the first view is shown and the second hidden, the button works just fine, but when I unhide the second layout, hide the first one, and proceed to click the button, that should be the same as the first one but in a different layout, nothing happens. I searched and find out, that this happens because the id is assigned only to the button shown in the first layout because of view hierarchy, but not the one in the second layout. How can I make both buttons react to the same action, without declaring a new button in each layout but instead reusing it?
I have used this type of layout. you can create Id different for both and inflate that view and give different name so You can differentiate both thing.
<?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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/image"
/>
<include android:id="+id/firstOne" layout="#layout/buttonLayout"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
android second one is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/image"
/>
<include android:id="+id/secondTwo" layout="#layout/buttonLayout"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
The Problem is both the layout are include in same layout file and the id of that
button are same so whenever you click on any of the button at the same time event will fire on both button like both are clicked.
So, you have to give the different id for both the button I hope it works fine..
You can add a different Id for each included layout:
<include android:id="+id/layout_a" layout="#layout/buttonLayout"/>
and
<include android:id="+id/layout_b" layout="#layout/buttonLayout"/>
and then use two findViewById to reach them:
btnCellA = (Button)thirdView.findViewById(R.id.layout_a).findViewById(R.id.btnCell);
btnCellB = (Button)thirdView.findViewById(R.id.layout_b).findViewById(R.id.btnCell);
I'm using the searchview at the top of my activity positioned just below the action bar, the problem is that the suggestions are displayed over the searchview so the user cant see the typed the text
<?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:orientation="vertical" >
<android.support.v7.widget.SearchView
android:id="#+id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.SearchView>
<RelativeLayout
android:layout_below="#id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map_container">
<!-- The map fragments will go here -->
</RelativeLayout>
</RelativeLayout>
no clue what the official answer even means. a work colleague aided me and I wanted to show how this can be achieved:
it can be done programatically by getting the textview as an AutoCompleteTextview:
imagine you have a searchview in xml like this:
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="10dp"
android:animateLayoutChanges="true"
android:paddingLeft="0dp"
app:closeIcon="#drawable/close_x_icon"
app:queryBackground="#drawable/search_bg_expanded"
app:searchHintIcon="#drawable/empty_drawable"
app:searchIcon="#null" />
then in code do this:
val searchText = searchView.findViewById<TextView>(android.support.v7.appcompat.R.id.search_src_text) as? AutoCompleteTextView
searchText?.dropDownAnchor = searchView.id
so once you cast it to an AutocompleteTextView you can change the anchor basically.
fixed by adding this view to the bottom of the relativelayout and setting it to the anchor
<View android:id="#+id/fragment_map.dropDownAnchor"
android:layout_below="#id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="0dp" />
I have a layout called wizard that has an empty ViewFlipper inside of it.
I have other views that include this 'wizard' and programmatically add children to the ViewFlipper inside the wizard. The problem I'm having is that one of these children has an EditText, and this View loses it's default style. I tried setting everything up in the xml file and the problem dissapeared, so the problem is in adding the views programmatically. I Also tried calling invalidate() on the main container (in the code below: #+id/recarga_celular_main), but nothing happens.
The Edit text can be seen in the following link: EditText weird style problem
The view is something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recarga_celular_main"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#drawable/theme_home_background"
android:gravity="center_horizontal|top" >
...
<CustomWizard
android:id="#+id/recargaCelular_wizard"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="#drawable/theme_layer_blue_bottom_black"
android:gravity="center_horizontal|center_vertical" >
</CustomWizard>
...
</RelativeLayout>
The 'wizard' is something like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/touch_wizard_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:gravity="center|top"
android:orientation="vertical" >
...
<ViewFlipper
android:id="#+id/wizard_flipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/aceptar_limpiar_btns"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
...
</LinearLayout>
In the java code, first I add the view to the flipper, and then I display the desired child:
flipper.addView(step.getView(), flipper.getChildCount() - 1);
...
flipper.setDisplayedChild(index);
EDIT
Manually set the default EditText style:
<EditText
style="#style/some_style"
android:background="#android:drawable/edit_text"
android:gravity="left"
android:hint="Celular" />