Android edittext focus change keyboard hides view - android

When I focus on another element in my app (landscape), the keyboard goes over my view that should be displayed, which I do not really want.
Code:
<activity
android:name=".activity.ReportsEditActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="#string/title_activity_reports_edit"
android:parentActivityName=".activity.MainActivity"
android:windowSoftInputMode="adjustPan|stateVisible">
</activity>
The edittext:
<EditText
android:id="#+id/report_template_grid_multi_line_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="#dimen/grid_element_top_and_bottom_padding"
android:layout_marginEnd="#dimen/grid_padding"
android:layout_marginStart="#dimen/grid_padding"
android:layout_marginTop="#dimen/grid_element_top_and_bottom_padding"
android:gravity="top|start"
android:inputType="textMultiLine"
android:paddingBottom="#dimen/grid_element_top_and_bottom_padding"
android:paddingEnd="#dimen/grid_element_top_and_bottom_padding"
android:paddingStart="#dimen/grid_element_top_and_bottom_padding"
android:paddingTop="#dimen/grid_element_top_and_bottom_padding"
android:scrollbars="vertical"
android:textColor="#color/darkGray"
android:textSize="#dimen/grid_text_size_small" />
This is fine:
But this is not fine, this occurs after clikcing on the edittext above the previous one when the keyboard is open

You could try android:windowSoftInputMode="adjustResize"
<activity
android:name=".activity.ReportsEditActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="#string/title_activity_reports_edit"
android:parentActivityName=".activity.MainActivity"
android:windowSoftInputMode="adjustResize">
</activity>

Related

Android 12 SplashActivity theme breaks CardView style

There is a custom AlertDialog in my app appearing in SplashActivity as follows:
The XML layout of the AlertDialog is something like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="wrap_content"
app:cardBackgroundColor="#FFFFFF"
app:cardCornerRadius="8dp">
<LinearLayout>
...
</LinearLayout>
</androidx.cardview.widget.CardView>
When I migrate my SplashActivity to new SplashScreen API in Android 12, I have to set its theme as follows:
<activity
android:name=".ui.SplashActivity"
android:screenOrientation="portrait"
android:exported="true"
android:theme="#style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
As a result, it breaks my custom AlertView as follows:
In conclusion, something breaks app:cardBackgroundColor attribute on CardView which is the root of my custom AlertView
If you look at the broken AlertView carefully, it seems there is a yellow layout over the CardView coming from nowhere.
Any ideas?

How to make button stay on the bottom when soft keyboard goes up

I have a button at the bottom of the screen and I want it to stay down even if soft keyboard goes up, but currently it goes up with soft keyboard. I tried to align the button to bottom but with no success.
Here is the code (buttons are within id/activity_form_button_frame):
<RelativeLayout>
<RelativeLayout
android:id="#+id/activity_form_button_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ImageButton
android:id="#+id/activity_form_next_button"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/black"
android:src="#drawable/next_btn_drawable"
android:scaleType="fitCenter"
android:padding="5dp"
/>
<Button
android:id="#+id/activity_form_sumbit_button"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/black"
android:text="SUBMIT"
android:textColor="#color/buttonBlue"
android:visibility="gone"
android:padding="15dp"
style="#android:style/TextAppearance.Large"/>
</RelativeLayout>
<FrameLayout
android:id="#+id/activity_form_fragmentcontainer"
android:layout_below="#id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/activity_form_button_frame"/>
</RelativeLayout>
In AndroidManifest.xml, set android:windowSoftInputMode="adjustPan" to your activity.
Like this.
<activity
android:windowSoftInputMode="adjustPan">
Or:
<activity
android:windowSoftInputMode="adjustPan|adjustResize">
Also you can do this Programmatically.
Use this code in onCreate() method:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Check this for Reference.
Try this
<activity
android:windowSoftInputMode="adjustPan">
or in code
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
try this....
<activity
android:windowSoftInputMode="adjustPan">
Try add in manifest to your activity attribute android:windowSoftInputMode.
Set it to adjustResize or adjustPan. One of these will work.
Inside your manifest file under your activity tag just add this line.
android:windowSoftInputMode="stateHidden|adjustResize"
For Example,
<activity
android:name="packagename.ClassName"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize" >
</activity>
And you are good to go.
Change at your AndroidManifest file and at activity to add property like
android:windowSoftInputMode="adjustResize"
to this direct to open keyboard to above button.
In your manifest file under activity tag add the following line.
android:windowSoftInputMode="adjustPan|adjustResize"
In your AndroidManifest.xml try this code:
<activity
android:name="com.facebook.FacebookActivity"
android:windowSoftInputMode="adjustPan|adjustResize"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
In my case, I was using <item name="android:windowFullscreen">true</item> in my theme. It was creating problem and I used android:windowSoftInputMode="adjustResize" along with that.
You can use android:layout_alignParentBottom="true" for that.

EditText is hidden by the softkeyboard in Android

I have a layout in an app with parallax effect on an edittext, my problem is **when I tap on the edittext softkeyboard hides my editext?**Can anybody please help me for this, I have searched for it and found about "WindowsoftInputmode" which is not working in my case.
Code in manifest
<activity
android:name="one.tusk.stush.activities.NewPostDetailActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|adjustPan" >
You should only use android:windowSoftInputMode="adjustResize".
If this is not enough, you might need to add the property android:fitsSystemWindows="true" to the root layout containing your EditText.
Try this in your manifest,
<activity
android:name=".rapcalsy.MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Change your layout according this,
dont miss the line which is
android:isScrollContainer="true"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:orientation="vertical">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#000000"
android:padding="0dp"
android:stretchColumns="*">
...
</TableLayout>
</ScrollView>
Please try this out.
Set an android:softInputMode attribute to adjustResize in Manifest and put the parent layout inside a ScrollView. Hope this helps.
I tried a bit with as you said then i got this working
edit the your manifest file
<activity
android:name="one.tusk.stush.activities.NewPostDetailActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible" >
and then add below line of code in oncreate of java class
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
So that keyboard will not shown to you directly/always

How to enable Split Action Bar?

I want to create an android application which has 3 sliding tab panel and each of them will 5 button (save,new,delete,exit..).
What I want is exactly as follow:
I created sliding tab panel.And for 5 button, I added split action bar.But It works as normal split action bar.My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.belsoft.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Where is my wrong?
To implement splitActionBar:
Just add android:uiOptions="splitActionBarWhenNarrow" to your activity tag in theAndroidManifest.xml like this...
`<activity
android:name=".MainActivity"
android:uiOptions="splitActionBarWhenNarrow">`<br>
You can read more here and here
NOTE: It is available ONLY for handset devices with a screen width
of 400dp.
To create a custom bottom toolbar:
If you want to set it for all devices, please check my answer (find a post starting with Creating custom bottom toolbar) here:
Creating custom bottom toolbar
I've already created a simple app which should demonstrate you how to
begin
Creating a custom ViewGroup
Here's my activity_main.xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<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:padding="0dp"
tools:context="com.example.piotr.myapplication.MainActivity">
<LinearLayout
android:id="#+id/show_pdf"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#color/primary_material_light"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_cut_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_copy_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_paste_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_share_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_moreoverflow_mtrl_alpha"/>
</LinearLayout>
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"/>
</RelativeLayout>
As you can see my parent ViewGroup is RelativeLayout, which simply
allows me to create a view at the bottom of screen.
Notice that I set layout padding to zero (I think: setting layout
margin to zero here is not necessary, the same effect). If you'd
change it, the toolbar won't use full width and it won't stick with
bottom of the screen.
Then I added a Linear Layout with hardcoded height which is:
android:layout_height="40dp"
I wanted it, that my bottom toolbar would take full available width so
I set it as match_parent.
Next, I added some ImageButton views with images from Android
library.
There you have two possibilities:
if you really want to have a toolbar like in above example just remove in every ImageButton view this line:
android:layout_weight="1"
After removing weights and some buttons you would get a view pretty
similar to expected:
if you want to take the full width and make every button with the same size use in your project weight as in this mine example.
Now let's go to my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.piotr.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateVisible|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
In that file I'd added as you can see only one additional line:
android:windowSoftInputMode="stateVisible|adjustResize">
to make sure that device keyboard won't hide my custom bottom toolbar.
From: How to add a bottom menu to Android activity
If you have any question please free to ask.
Hope it help

Android App to always stay in Landscape

I have looked Here but am still unable to tackle my problem.
I have recently jumped into android (headfirst) and have been messing around. I would like my application to only run in Landscape mode no matter which way the screen is tilted.
My home screen is basically a page with a background and a few buttons that are aligned on the right side.
Here is my XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft = "450px"
android:paddingRight = "60px"
android:paddingTop="25px"
//I have tried adding orientation commands here like the one below??
android:screenOrientation="landscape"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "#drawable/sign"
>
<Button
android:id="#+id/Button1"
android.layout_height="60px"
android.layout_width="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Button1"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/Button2"
android.layout_height="60px"
android.layout_width="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Button2"/>
add this line in your manifest.xml file.
<activity android:name=".activity" android:screenOrientation="portrait"></activity>
if you want only landscape orientation then change landscape instead of portrait
see this How to set android show vertical orientation?
Add the following property all the activites in your manifest file:
android:screenOrientation="landscape"
for example:
<activity android:name=".MainActivity" android:screenOrientation="landscape" " >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you can add this property in your application tag also in the manifest file .
hope this help you to solve your issue.
You need to put android:screenOrientation="landscape" on the activity tag in your AndroidManifest.xml file.
Reference: http://developer.android.com/guide/topics/manifest/activity-element.html

Categories

Resources