hide keyboard in android? - java

I am new to android development.
I am creating an application in which when app launches the edittextfield getfocus automatically and the keyboard pop-up.I want to hide the keyboard by default and show when edittextField get focus. I have tried this method but it's not working.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

Change your manifest file:
pput it there:
(on your especific activity)
android:windowSoftInputMode="stateHidden"

Declaring android:windowSoftInputMode="stateHidden" in corresponding activity tag on Manifest file will solve this. But study about this attribute here.
android:windowSoftInputMode

Related

Android: playing video in picture-in-picture mode ( multiple instances when click on close button)

For my android application, when a user play a video, a new activity (VideoPlay) starts in pip mode.
Manifest (Video Play)
<activity
android:name=".PlayVideo"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:theme="#style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity"
android:supportsPictureInPicture="true"
android:configChanges=
"screenSize|smallestScreenSize|screenLayout|orientation"/>
The problem is when i click on close button "X" of the pip screen, a new instance of my app is created.
how to handle this problem ? thank you
That is not another instance of your app, but rather a different task which houses your PlayVideo activity. To prevent showing your activity in recents screen, you can add android:excludeFromRecents="true" in the manifest attributes of your PlayVideo activity.
Also, if you're force closing your PlayVideo activity in some way other than user interaction like backpress, you may like to call finishAndRemoveTask() instead of just finish() as calling finish() will not remove your activity from recents.

Move EditText (or a layout) above the keyboard when you click a fab

So, I saw that thing in the Todoist app. When you click the add fab, the keyboard pops up with some layout above it where you can enter text and set some things. How can I do it?
This is how the thing actually looks:
Is there some example on how this is done?
(please don't mind that this is the iOS version of the app, I don't own a android device)
Make bottom sheet with fragment and edit text in fragment,and set button fab to show bottom sheet when clicked,,you can set the bottomsheet visibility GONE if you want
Add this android:windowSoftInputMode="stateHidden"
line in your Activity block in manifist.xml file like this
<activity
android:name=".Activities.DashboardActivity"
android:label="#string/title_activity_dashboard"
android:windowSoftInputMode="stateHidden"
android:theme="#style/AppTheme.NoActionBar">
</activity>

Bluetooth discoverability request and screen orientation

Asking user the permission to turn device discoverable with the following snippet
final Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(intent, BT_REQUEST);
causes the following system dialog to show up in portrait mode while my calling activity is in landscape, which is not a good user experience.
Many landscape only bluetooth apps I tried from the Play Store seem to suffer the same problem.
Is there any way to force the dialog to appear in landscape mode?
I tried to override system activity orientation from manifest, without success
<activity android:name="com.android.settings.bluetooth.RequestPermissionActivity"
android:screenOrientation="landscape" />

Actionabar issues coming from full screen

I got a full screen activity that leads to an activity with an action bar. When the scond activity loads, the actionbar is half hidden by the title menu.
Why is this happening and what can I do to prevent it?
EDIT: as seen below, the title bar hides some of the action bar.
1 ) You have to keep same theme for all activity ,put actionbar activity them in application tag in manifest file
2) If you want to use full screen activity then getSupportActionBar().hide(); If you have Simle activity and Actionbar activity then while launching simple Actionbar activity to Simple activity creates problem.
check your activity deceleration in the manifest file. Declarer your activity like this.
<activity
android:name="com.android.MainActivity"
android:theme="#android:style/Theme.Light.NoTitleBar">
</activity>

why does my android keyboard opens automatically?

I have this Layout.
every time it's opened, the android keyboard appears
why is that?
how can I avoid this?
Add this to your manifest file, You can avoid that.
<activity
android:name="Your_Activity"
android:windowSoftInputMode="stateAlwaysHidden" >
</activity>
If the EditText has requestFocus,then keyboard might display automatically. It has nothing to do with your xml code.
Add the following line to your Manifest File inside each Activity tab
android:windowSoftInputMode="stateAlwaysHidden"
or add the following to your parent layout in that activity
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
Strange ! I thought Screen which has editText only get focus.
Try this => Stop EditText from gaining focus at Activity startup
Android opens the OnScreenKeyboard automatically if you have an EditText focussed .
You can prevent that by adding following into your Activity's onCreate method.
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Categories

Resources