How to stop soft keyboard appear by default in android - java

I am writing an android application with two EditText on the main activity. My problem is that once the main activity starts the soft keyboad automatically appears. I want the soft keyboard to appear only when the user clicks on the EditText component. How can I accomplish this?

In your activity, in your onCreate method, put the following
edittext.setFocused(false);
And then afterwards (in a different method, maybe an onClickListener for your edittext) put
edittext.setFocused(true);
Also you could put the below line in you manifest, in the the activity section, just below the android:name attribute
android:windowSoftInputMode="stateUnchanged"

Try this,
<EditText android:id="#+id/edit_text_id"
..
android:focusable="false" />

if you want to manage the inpt events , take a look on this part :
==> http://developer.android.com/guide/topics/ui/ui-events.html

Related

How to automatically focus on Plaintext after going to another activity

I have an empty activity with just the PlainText on it.
I want it so that after the user taps on the button that directs him to the empty activity it automatically selects/focuses on the PlainText bringing out the built-in android keyboard ready to get user's input.
I tried
android:focusedByDefault="true"
but that doesn't seem to do anything after going to the empty activity.
You can try to do
editText.requestFocus();
on your empty activity's onCreate() method
Set Focus on EditText
See here.
Note: Normally the general problem is "hot to remove auto focus" from EditText so it focuses automatically, so maybe you changed some attributes from your xml, please share your empty activity xml with us.
You can try to do
editText.setFocusableInTouchMstrong textode(true);
editText.setFocusable(true);
editText.requestFocus();
on your empty activity's onCreate() method

How to hide Title Bar of a pop-up activity

I created an activity which is shown as pop up/ Dialog by following answers given in this question.
I did it by adding these lines in AndroidManifest
<activity
android:name=".package.Activity"
android:theme="#style/Theme.AppCompat.Light.Dialog.Alert" />
It works well as intended but the problem it shows Appname as title. I want to make it appear as AlertDialog. How to fix this?
I also cant use setTitle("") or label="" because empty space is left where appname was before.
Add this code to the top of the onCreate() method of the Activity:
setTheme(R.style.{style}
The {style} should be ended with NoActionBar. i.e. R.style.Theme_AppCompat_NoActionBar
And most importantly, add the code before these two lines of code (add it to the top of the method):
super.onCreate(savedInstanceState);
setContentView(R.layout.{your layout});
Hope this answer helped!
You can simply call the setTitle("") function from within your Activity.

Android - One button changing to next screen created. How to do next one?

I created very simple button directing to new screen from this tutorial:
www.mkyong.com/android/android-activity-from-one-screen-to-another-screen
and it works fine.
The question is how to make a button returning from main2.xml to main.xml (and every next one button). I am not very good at it yet and logically i tried to create button with #id:button2 and a class App3Activity.java the same as App2Activity.java but changed button1 to button2 and main to main2. However, it crashed. What is wrong ?
Crash log: http://pastebin.com/bmcVMmJ0
Code: http://pastebin.com/8p6GwG3u
there are many reason regarding your scenario
Activity not defined in Manifest file
Calling button in activity may not getting its view to trigger its functionality
using 2 different XML in same Activity
Intent not instantiated properly
Context Switching is not proper
there are many reasons behind your its an open ended Question unless you provide stacktace (Logcat) or code that you are working with
App3Activity is not declared in manifest file.
AppActivity is starting App2Activity, but App2Activity doesn't initialize button and click listener.

Android Pre-Load Splash Screen

Hopefully this isn't a dumb question, but when I initially click on my app, a kind of splash screen first appears for a few seconds with just a title bar indicating the name of the app and nothing else - then the app loads as expected. Is there any way to remove this screen?
The system looks into your AndroidManifest.xml to find out what is the theme of the main Activity. If you don't specify it manually, it assumes the application theme, if you don't specify application theme then the default theme is used. The system then creates the "splash screen" solely acoording to the theme.
So if you want to remove it, create a theme that has a transparent background and no ActionBar. And in onCreate() you probably want to change the theme again (or just change the background and show the ActionBar).
But it's better to have some visible "splash screen". Otherwise if you click on the icon, you won't see nothing for 1 - 2 seconds, which is quite weird, almost no app does this.
Initializing more resources on
onCreate()
may take some time. Try not to overload onCreate() method of Activity.
Try not to deep down more than 30 levels inside the xml layout file. which can also take up some time to initialize .
setContentView(R.layout.main)

How can I make sure my EditText always has focus?

Whenever an activity starts, I want to make sure my EditText has focus and has the cursor inside. Basically I want to make sure the keyboard is up.
In the EditText tag in your xml layout, add the tag
<requestFocus />
You may also do the programatically by calling the method. editText.requestFocus.

Categories