android


Disable soft keyboard for an Edittext


I have an EditText where I want to handle the inputs myself, so I don't want the soft keyboard to show up when I click it (or when selection changes, focus changed, long clicked, etc). However, I still want to be able select the text, change cursor position, copy/past, etc.
I have tried putting android:windowSoftInputMode="stateAlwaysHidden" in the manifest, but that doesn't seems to do much. I also tried adding the following
edittext.setOnTouchListener(new OnTouchListener() {
#Override public boolean onTouch(View v, MotionEvent event) {
EditText edittext = (EditText) v;
int inType = edittext.getInputType(); // Backup the input type
edittext.setInputType(InputType.TYPE_NULL); // Disable standard keyboard
edittext.onTouchEvent(event); // Call native handler
edittext.setInputType(inType); // Restore input type
return true; // Consume touch event
}
});
which disables the keyboard, but also prevent the cursor from working.
Currently I'm basically trying to add listeners for all the situations where the keyboard might pop up to toggle it off, but this is very clunky and I can't catch all the cases. Is there a better way to disable the soft keyboard for a particular EditText or fragment?
Try this code.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Disable IME for this application
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
setContentView(R.layout.activity_layout);

Related Links

Android - NullReferenceException on Scroll/Drag-and-Drop (setDragFocus)
Facebook Deep Linking back navigation issue in android
Instantiate custom view programmatically the right way
how can i determine internet speed in my android application
Android Recycler view inside Viewpager and Recyclerview and Common Pattern
Android Studio Not Working Properly
Android Firebase How to check if there are pending requests
Android Pay: BadParcelableExcaption for com.google.android.gms.wallet.shared.BuyFlowConfig
I put ViewPager(look like a gallery) in Recyclerview, But Memory leaked
Replacing ListFragment with Fragment in android
What are the referrer details if we download app directly from Playstore? I mean what will be the value for utm_source and all?
Volley request is not receiving
Latest version of gradle can't be found
What are the specific keys(platform.x509.pem and platform.pk8) used in Lenovo TAB A7-30HC
How do I open Thursby SubRosa from another iOS App?
TransactionTooLargeException in SyncAdapter on get count of table

Categories

HOME
go
fabricjs
search
c++11
amp-html
youtube-data-api-v3
alsa
big-o
pyqt4
zip
angularfire2
pkcs#11
okhttp
fosrestbundle
pcl-crypto
windows-ce
activecollab
ipmitool
android-intent
symfony-2.8
standards
chargify
fileserver
soci
cfml
delphi-xe5
joptionpane
ckfinder
android-sharedpreferences
bringtofront
user-defined-functions
magento-1.8
xbox
papaparse
contacts
joomla2.5
fossil
zoomify
bc
recurrent-neural-network
css-position
hackintosh
setup.py
mcustomscrollbar
skylink
android-softkeyboard
show-hide
openal
opennms
clarifai
sonarlint-eclipse
dbcontext
x-ray
posixct
magic-draw
pair-programming
stdmap
context-sensitive-grammar
colorbar
git-flow
avx
offline.js
swingworker
filenet
vcloud-director-rest-api
smartfoxserver
vorpal.js
avspeechsynthesizer
cortex-m
fink
exim4
jparsec
contentcontrol
toran-proxy
rewrite
file-move
google-books
coda
pax-exam
airbrake
pyobjc
dnssec
nsurlsessiondatatask
bufferedinputstream
uvc
procedural-programming
infosphere-spl
filesplitting
big-ip
tweenlite
angular-carousel
named-parameters
alternate
drupal-nodes
inputmismatchexception
script#
scringo
time.h
epiceditor
dolby-audio-api
mysql-error-2013
subgraph
mapping-by-code
kqueue
floating-point-exceptions
google-maps-mobile
listactivity
drawtobitmap
msr
svk
cac
diagrams
facebook-iframe
maven-1
cfwindow
product-management
java1.4
online-storage

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App