Keyboard break layout and behaviour - java

I have a fragment with some views like EditText, ViewFlipper and RecyclerView.
But I have an issue with the keyboard: when the keyboard appear, some of my views become whites and my RecyclerView is empty or when I tap on an item I have to scroll him to handle the event.
Do you know why the soft keyboard break the layout and behavior? And do you know how to solve this?
Thanks you for your help.
EDIT : Seems solved
I've found a solution which seems to work:
I change the softInputMode in the onCreate() method to adjustNothing
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
}
then in onDestroy I set the previous mode, here adjustPan
override fun onDestroy() {
super.onDestroy()
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
}

You can simply switch your Activity's windowSoftInputMode flag to adjustPan in your AndroidMainfest.xml file inside your activity tag.
Check the official documentation for more info.
https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
<activity
...
android:windowSoftInputMode="adjustPan">
</activity>

Related

Back button on action bar

when I create a new activity, Android Studio show me this photo:
It have a Back button but activity haven't it. how can I Make visible it?
put getSupportActionBar().setDisplayHomeAsUpEnabled(true); into onCreate() method in your activity class
In manifest declare the activity as a parent activity to get this button like this
<activity android:name="com.owletogroceries.activity.RewardsActivity"/>
<activity android:name="OrderConfirmationActivity"
android:parentActivityName="ProductActivity"/>

Android dialog theme makes setContentView crash the application

I'm applying this theme from manifest :
<activity
android:name=".ui.rate.MyActivity"
android:theme="#android:style/Theme.Dialog">
</activity>
With this the application crash on setContentView() of MyActivity. If I remove it there is no crash but I need this theme
In the activity onCreate() i'm doing this :
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_rate);
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Even if I remove the first and third lines the applicatio ncrash the same way. It's really the dialog theme that's causing the crash
How can I set it so that Android accept it ?
You can use Theme.AppCompat.Dialog as the theme of your activity to avoid
compatibility problem.
The activity will be presented as a dialog.
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Dialog">
</activity>
As for the title, you can use setTitle("Hola!"); to change it.
If you wanna remove the title, just call:
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
for android:theme="#style/Theme.AppCompat.Dialog",
and:
requestWindowFeature(Window.FEATURE_NO_TITLE);
for android:theme="#android:style/Theme.Dialog".

Removing Android Titlebar is not working (android studio)

Good morning. I've been using android studio to try to make an activity/whole app fullscreen.
There are two methods I have tried, one is in the manifest:
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
</activity>
(and another attempt in the manifest)
android:theme="#style/FullscreenTheme" >
(and another attempt in the manifest)
android:theme="#android:style/Theme.NoTitleBar">
And the other is in code (onCreate)
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Time and time again the bar at the top appears in all my activities as seen in the image below.
Does anyone know how to make that dissapear so its fullscreen please.
1) Add theme for Activity
<activity
android:name=".MyActivity"
android:theme="#android:style/Theme.NoTitleBar"/>
OR
2) Handle in Activity
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.main_layout);
In the onCreate of your activities, use
getActionBar().hide();
I think this will work android:theme="#android:style/Theme.Holo.NoActionBar"
I usually do this:
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
.
.
.

Android notification bar persists on the all Application screen(never goes)

I have a screen in my app with a button to set date/time in the OS. I use startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS)) to open the android's date/time screen .
After setting the date/time , i return to my app screen using the back button in the android's status(notification) bar. After this, the notification bar never dissappears from my app screens. Its persistent until i restart my application. Is there a way to remove the notification bar?
I have added the line "android:theme="#android:style/Theme.NoTitleBar.Fullscreen" to all my activities and even at at the application level(just inside )
But still it never goes
Here is a part of my manifest
<activity
android:name="com.cyberonics.progsoundapp.ui.AlarmSettingScreen"
android:configChanges="keyboardHidden|orientation"
android:label="#string/title_activity_alarm_setting_screen"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
I also have the following code in my activity class
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN) before SetContentView()
Is there anything else i am missing?
Request your guidance on this
Thank you

List disappears when phone rotated(Android)

In my app, in the OnCreate method, I create a list(using an add button) or I fetch it from a saved file. My function works fine and I am able to create and fetch the list until I rotate the phone(vertical -> horizontal). The list then disappears. I am still able to click the buttons on screen, but it seems I have no items in the list.Any help appreciated. Thank You in advance.
add this tag in Activity tag in manifest
android:configChanges="keyboardHidden|orientation"
and add this in activity code
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
in the same activity..
this happens because each time your screen orientation is changed onCreate() method of the Activity will be called every time
This post from developer.android.com could help too!
It would be wise if you would add screenSize at android:configChanges="keyboardHidden|orientation" aswell i.e
android:configChanges="orientation|keyboardHidden|screensize"

Categories