How to disable EditText in Android











up vote
65
down vote

favorite
10












How can I disable typing in an EditText field in Android?










share|improve this question




















  • 1




    Disable Keyboard on input in EditText ?
    – Kartik Domadiya
    May 4 '11 at 6:13










  • There are two editText fields.First is for entering email.if the email is valid then the second editText field is to be enabled.but the problem is while typing an invalid email and clicking on the next button on the soft keyboard it goes to the second text field and can enter data eventhough i've made edittext.setEnabled(false).i am using android 2.3.1
    – aj10
    May 4 '11 at 6:46















up vote
65
down vote

favorite
10












How can I disable typing in an EditText field in Android?










share|improve this question




















  • 1




    Disable Keyboard on input in EditText ?
    – Kartik Domadiya
    May 4 '11 at 6:13










  • There are two editText fields.First is for entering email.if the email is valid then the second editText field is to be enabled.but the problem is while typing an invalid email and clicking on the next button on the soft keyboard it goes to the second text field and can enter data eventhough i've made edittext.setEnabled(false).i am using android 2.3.1
    – aj10
    May 4 '11 at 6:46













up vote
65
down vote

favorite
10









up vote
65
down vote

favorite
10






10





How can I disable typing in an EditText field in Android?










share|improve this question















How can I disable typing in an EditText field in Android?







android android-edittext disabled-input






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:23









LAD

1,7981720




1,7981720










asked May 4 '11 at 6:06









aj10

3931410




3931410








  • 1




    Disable Keyboard on input in EditText ?
    – Kartik Domadiya
    May 4 '11 at 6:13










  • There are two editText fields.First is for entering email.if the email is valid then the second editText field is to be enabled.but the problem is while typing an invalid email and clicking on the next button on the soft keyboard it goes to the second text field and can enter data eventhough i've made edittext.setEnabled(false).i am using android 2.3.1
    – aj10
    May 4 '11 at 6:46














  • 1




    Disable Keyboard on input in EditText ?
    – Kartik Domadiya
    May 4 '11 at 6:13










  • There are two editText fields.First is for entering email.if the email is valid then the second editText field is to be enabled.but the problem is while typing an invalid email and clicking on the next button on the soft keyboard it goes to the second text field and can enter data eventhough i've made edittext.setEnabled(false).i am using android 2.3.1
    – aj10
    May 4 '11 at 6:46








1




1




Disable Keyboard on input in EditText ?
– Kartik Domadiya
May 4 '11 at 6:13




Disable Keyboard on input in EditText ?
– Kartik Domadiya
May 4 '11 at 6:13












There are two editText fields.First is for entering email.if the email is valid then the second editText field is to be enabled.but the problem is while typing an invalid email and clicking on the next button on the soft keyboard it goes to the second text field and can enter data eventhough i've made edittext.setEnabled(false).i am using android 2.3.1
– aj10
May 4 '11 at 6:46




There are two editText fields.First is for entering email.if the email is valid then the second editText field is to be enabled.but the problem is while typing an invalid email and clicking on the next button on the soft keyboard it goes to the second text field and can enter data eventhough i've made edittext.setEnabled(false).i am using android 2.3.1
– aj10
May 4 '11 at 6:46












14 Answers
14






active

oldest

votes

















up vote
37
down vote



accepted










I think its a bug in android..It can be fixed by adding this patch :)

Check these links
question 1
and
question 2



Hope it will be useful.






share|improve this answer



















  • 1




    Thanks .it works :)
    – aj10
    May 4 '11 at 7:03






  • 94




    For those who'd rather see the code right here rather than use a hyperlink: editText.setEnabled(false);, in combination with editText.setFocusable(false); will achieve this.
    – Mxyk
    Jan 9 '12 at 15:00








  • 5




    The same works with XML: android:enabled="false" and android:focusable="false". Thanks guys!
    – jelies
    Jan 21 '13 at 19:45


















up vote
56
down vote













you can use EditText.setFocusable(false) to disable editing
EditText.setFocusableInTouchMode(true) to enable editing;






share|improve this answer



















  • 2




    It does not work for me
    – ann
    Jul 9 '14 at 9:15






  • 4




    This was my issue. I assumed that after setFocusable(false) I could just flip setFocusable(true)... not the case. Setting setFocusableInTouchMode(true) did the trick for me.
    – timgcarlson
    Jul 17 '15 at 22:55


















up vote
34
down vote













In code:



editText.setEnabled(false);


Or, in XML:



android:editable="false"





share|improve this answer




























    up vote
    10
    down vote













    Assuming editText is you EditText object:



    editText.setEnabled(false);





    share|improve this answer

















    • 8




      It doesn't work!
      – meh
      Oct 16 '12 at 13:38


















    up vote
    8
    down vote













    Just set focusable property of your edittext to "false" and you are done.



    <EditText
    android:id="@+id/EditTextInput"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:gravity="right"
    android:cursorVisible="true">
    </EditText>


    Below options doesn't work



    In code:



    editText.setEnabled(false);
    Or, in XML:
    android:editable="false"






    share|improve this answer






























      up vote
      8
      down vote













      You can try the following method :



       private void disableEditText(EditText editText) {
      editText.setFocusable(false);
      editText.setEnabled(false);
      editText.setCursorVisible(false);
      editText.setKeyListener(null);
      editText.setBackgroundColor(Color.TRANSPARENT);
      }


      Enabled EditText :



      Enabled EditText



      Disabled EditText :



      Disabled EditText



      It works for me and hope it helps you.






      share|improve this answer























      • good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null);
        – Syed Raza Mehdi
        Aug 30 '16 at 9:45


















      up vote
      4
      down vote













      Edittext edittext = (EditText)findViewById(R.id.edit);
      edittext.setEnabled(false);





      share|improve this answer




























        up vote
        2
        down vote













        The below code disables the EditText in android



        editText.setEnabled(false);





        share|improve this answer























        • just set focusable property of your edittext to "false" and you are done. <!-- begin snippet: js hide: false --> <!-- language: lang-html --> <EditText android:id="@+id/EditTextInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:gravity="right" android:cursorVisible="true"> </EditText> <!-- end snippet -->
          – ramit girdhar
          Nov 25 '14 at 11:26




















        up vote
        2
        down vote













        edittext.setFocusable(false); 
        edittext.setEnabled(false);

        InputMethodManager imm = (InputMethodManager)
        getSystemService(Context.INPUT_METHOD_SERVICE);

        imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
        //removes on screen keyboard





        share|improve this answer






























          up vote
          1
          down vote













          To disable a edittext in android:



          editText.setEnabled(false);





          share|improve this answer























          • not working in some devices with version < 2.3.
            – Ketan Ahir
            Dec 10 '13 at 9:10




















          up vote
          1
          down vote













          You can write edittext.setInputType(0) if you want to show the edittext but not input any values






          share|improve this answer






























            up vote
            0
            down vote













            Write this in parent:



            android:descendantFocusability="beforeDescendants"
            android:focusableInTouchMode="true"


            Example:



            <RelativeLayout 
            android:id="@+id/menu_2_zawezanie_rl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/menu_2_horizontalScrollView"
            android:descendantFocusability="beforeDescendants"
            android:focusableInTouchMode="true"
            android:orientation="horizontal"
            android:background="@drawable/rame">

            <EditText
            android:id="@+id/menu2_et"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/menu2_ibtn"
            android:gravity="center"
            android:hint="@string/filtruj" >
            </EditText>
            <ImageButton
            android:id="@+id/menu2_ibtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:background="@null"
            android:src="@drawable/selector_btn" />







            share|improve this answer






























              up vote
              0
              down vote













              According to me...if you have already declared the edittext in the XML file and set the property in the XML file "android:enabled=false" and disable at runtime to it at that time in java file adding only 2 or 3 lines




              1. First create the object

              2. Declare EditText et1;


              3. Get by id



                et1 = (EditText) FindViewById(R.id.edittext1);
                et1.setEnabled(false);




              You can do enable or disable to every control at run time by java file and design time by XML file.






              share|improve this answer






























                up vote
                0
                down vote













                Enable:



                private void enableEditText() {
                mEditText.setFocusableInTouchMode(true);
                mEditText.setFocusable(true);
                mEditText.setEnabled(true);
                }


                Disable:



                private void disableEditText() {
                mEditText.setEnabled(false);
                mEditText.setFocusable(false);
                mEditText.setFocusableInTouchMode(false);
                }





                share|improve this answer





















                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5879250%2fhow-to-disable-edittext-in-android%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  14 Answers
                  14






                  active

                  oldest

                  votes








                  14 Answers
                  14






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  37
                  down vote



                  accepted










                  I think its a bug in android..It can be fixed by adding this patch :)

                  Check these links
                  question 1
                  and
                  question 2



                  Hope it will be useful.






                  share|improve this answer



















                  • 1




                    Thanks .it works :)
                    – aj10
                    May 4 '11 at 7:03






                  • 94




                    For those who'd rather see the code right here rather than use a hyperlink: editText.setEnabled(false);, in combination with editText.setFocusable(false); will achieve this.
                    – Mxyk
                    Jan 9 '12 at 15:00








                  • 5




                    The same works with XML: android:enabled="false" and android:focusable="false". Thanks guys!
                    – jelies
                    Jan 21 '13 at 19:45















                  up vote
                  37
                  down vote



                  accepted










                  I think its a bug in android..It can be fixed by adding this patch :)

                  Check these links
                  question 1
                  and
                  question 2



                  Hope it will be useful.






                  share|improve this answer



















                  • 1




                    Thanks .it works :)
                    – aj10
                    May 4 '11 at 7:03






                  • 94




                    For those who'd rather see the code right here rather than use a hyperlink: editText.setEnabled(false);, in combination with editText.setFocusable(false); will achieve this.
                    – Mxyk
                    Jan 9 '12 at 15:00








                  • 5




                    The same works with XML: android:enabled="false" and android:focusable="false". Thanks guys!
                    – jelies
                    Jan 21 '13 at 19:45













                  up vote
                  37
                  down vote



                  accepted







                  up vote
                  37
                  down vote



                  accepted






                  I think its a bug in android..It can be fixed by adding this patch :)

                  Check these links
                  question 1
                  and
                  question 2



                  Hope it will be useful.






                  share|improve this answer














                  I think its a bug in android..It can be fixed by adding this patch :)

                  Check these links
                  question 1
                  and
                  question 2



                  Hope it will be useful.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 9 '14 at 9:22









                  ann

                  5881919




                  5881919










                  answered May 4 '11 at 7:01









                  Midhun

                  41233




                  41233








                  • 1




                    Thanks .it works :)
                    – aj10
                    May 4 '11 at 7:03






                  • 94




                    For those who'd rather see the code right here rather than use a hyperlink: editText.setEnabled(false);, in combination with editText.setFocusable(false); will achieve this.
                    – Mxyk
                    Jan 9 '12 at 15:00








                  • 5




                    The same works with XML: android:enabled="false" and android:focusable="false". Thanks guys!
                    – jelies
                    Jan 21 '13 at 19:45














                  • 1




                    Thanks .it works :)
                    – aj10
                    May 4 '11 at 7:03






                  • 94




                    For those who'd rather see the code right here rather than use a hyperlink: editText.setEnabled(false);, in combination with editText.setFocusable(false); will achieve this.
                    – Mxyk
                    Jan 9 '12 at 15:00








                  • 5




                    The same works with XML: android:enabled="false" and android:focusable="false". Thanks guys!
                    – jelies
                    Jan 21 '13 at 19:45








                  1




                  1




                  Thanks .it works :)
                  – aj10
                  May 4 '11 at 7:03




                  Thanks .it works :)
                  – aj10
                  May 4 '11 at 7:03




                  94




                  94




                  For those who'd rather see the code right here rather than use a hyperlink: editText.setEnabled(false);, in combination with editText.setFocusable(false); will achieve this.
                  – Mxyk
                  Jan 9 '12 at 15:00






                  For those who'd rather see the code right here rather than use a hyperlink: editText.setEnabled(false);, in combination with editText.setFocusable(false); will achieve this.
                  – Mxyk
                  Jan 9 '12 at 15:00






                  5




                  5




                  The same works with XML: android:enabled="false" and android:focusable="false". Thanks guys!
                  – jelies
                  Jan 21 '13 at 19:45




                  The same works with XML: android:enabled="false" and android:focusable="false". Thanks guys!
                  – jelies
                  Jan 21 '13 at 19:45












                  up vote
                  56
                  down vote













                  you can use EditText.setFocusable(false) to disable editing
                  EditText.setFocusableInTouchMode(true) to enable editing;






                  share|improve this answer



















                  • 2




                    It does not work for me
                    – ann
                    Jul 9 '14 at 9:15






                  • 4




                    This was my issue. I assumed that after setFocusable(false) I could just flip setFocusable(true)... not the case. Setting setFocusableInTouchMode(true) did the trick for me.
                    – timgcarlson
                    Jul 17 '15 at 22:55















                  up vote
                  56
                  down vote













                  you can use EditText.setFocusable(false) to disable editing
                  EditText.setFocusableInTouchMode(true) to enable editing;






                  share|improve this answer



















                  • 2




                    It does not work for me
                    – ann
                    Jul 9 '14 at 9:15






                  • 4




                    This was my issue. I assumed that after setFocusable(false) I could just flip setFocusable(true)... not the case. Setting setFocusableInTouchMode(true) did the trick for me.
                    – timgcarlson
                    Jul 17 '15 at 22:55













                  up vote
                  56
                  down vote










                  up vote
                  56
                  down vote









                  you can use EditText.setFocusable(false) to disable editing
                  EditText.setFocusableInTouchMode(true) to enable editing;






                  share|improve this answer














                  you can use EditText.setFocusable(false) to disable editing
                  EditText.setFocusableInTouchMode(true) to enable editing;







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 6 '12 at 7:57









                  Aliaksei Kliuchnikau

                  11.7k34865




                  11.7k34865










                  answered Feb 6 '12 at 7:24









                  chaitanya

                  1,28111310




                  1,28111310








                  • 2




                    It does not work for me
                    – ann
                    Jul 9 '14 at 9:15






                  • 4




                    This was my issue. I assumed that after setFocusable(false) I could just flip setFocusable(true)... not the case. Setting setFocusableInTouchMode(true) did the trick for me.
                    – timgcarlson
                    Jul 17 '15 at 22:55














                  • 2




                    It does not work for me
                    – ann
                    Jul 9 '14 at 9:15






                  • 4




                    This was my issue. I assumed that after setFocusable(false) I could just flip setFocusable(true)... not the case. Setting setFocusableInTouchMode(true) did the trick for me.
                    – timgcarlson
                    Jul 17 '15 at 22:55








                  2




                  2




                  It does not work for me
                  – ann
                  Jul 9 '14 at 9:15




                  It does not work for me
                  – ann
                  Jul 9 '14 at 9:15




                  4




                  4




                  This was my issue. I assumed that after setFocusable(false) I could just flip setFocusable(true)... not the case. Setting setFocusableInTouchMode(true) did the trick for me.
                  – timgcarlson
                  Jul 17 '15 at 22:55




                  This was my issue. I assumed that after setFocusable(false) I could just flip setFocusable(true)... not the case. Setting setFocusableInTouchMode(true) did the trick for me.
                  – timgcarlson
                  Jul 17 '15 at 22:55










                  up vote
                  34
                  down vote













                  In code:



                  editText.setEnabled(false);


                  Or, in XML:



                  android:editable="false"





                  share|improve this answer

























                    up vote
                    34
                    down vote













                    In code:



                    editText.setEnabled(false);


                    Or, in XML:



                    android:editable="false"





                    share|improve this answer























                      up vote
                      34
                      down vote










                      up vote
                      34
                      down vote









                      In code:



                      editText.setEnabled(false);


                      Or, in XML:



                      android:editable="false"





                      share|improve this answer












                      In code:



                      editText.setEnabled(false);


                      Or, in XML:



                      android:editable="false"






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 4 '11 at 6:13









                      Gabriel Negut

                      10.8k32842




                      10.8k32842






















                          up vote
                          10
                          down vote













                          Assuming editText is you EditText object:



                          editText.setEnabled(false);





                          share|improve this answer

















                          • 8




                            It doesn't work!
                            – meh
                            Oct 16 '12 at 13:38















                          up vote
                          10
                          down vote













                          Assuming editText is you EditText object:



                          editText.setEnabled(false);





                          share|improve this answer

















                          • 8




                            It doesn't work!
                            – meh
                            Oct 16 '12 at 13:38













                          up vote
                          10
                          down vote










                          up vote
                          10
                          down vote









                          Assuming editText is you EditText object:



                          editText.setEnabled(false);





                          share|improve this answer












                          Assuming editText is you EditText object:



                          editText.setEnabled(false);






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 4 '11 at 6:12









                          MByD

                          116k22223249




                          116k22223249








                          • 8




                            It doesn't work!
                            – meh
                            Oct 16 '12 at 13:38














                          • 8




                            It doesn't work!
                            – meh
                            Oct 16 '12 at 13:38








                          8




                          8




                          It doesn't work!
                          – meh
                          Oct 16 '12 at 13:38




                          It doesn't work!
                          – meh
                          Oct 16 '12 at 13:38










                          up vote
                          8
                          down vote













                          Just set focusable property of your edittext to "false" and you are done.



                          <EditText
                          android:id="@+id/EditTextInput"
                          android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:focusable="false"
                          android:gravity="right"
                          android:cursorVisible="true">
                          </EditText>


                          Below options doesn't work



                          In code:



                          editText.setEnabled(false);
                          Or, in XML:
                          android:editable="false"






                          share|improve this answer



























                            up vote
                            8
                            down vote













                            Just set focusable property of your edittext to "false" and you are done.



                            <EditText
                            android:id="@+id/EditTextInput"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:focusable="false"
                            android:gravity="right"
                            android:cursorVisible="true">
                            </EditText>


                            Below options doesn't work



                            In code:



                            editText.setEnabled(false);
                            Or, in XML:
                            android:editable="false"






                            share|improve this answer

























                              up vote
                              8
                              down vote










                              up vote
                              8
                              down vote









                              Just set focusable property of your edittext to "false" and you are done.



                              <EditText
                              android:id="@+id/EditTextInput"
                              android:layout_width="fill_parent"
                              android:layout_height="wrap_content"
                              android:focusable="false"
                              android:gravity="right"
                              android:cursorVisible="true">
                              </EditText>


                              Below options doesn't work



                              In code:



                              editText.setEnabled(false);
                              Or, in XML:
                              android:editable="false"






                              share|improve this answer














                              Just set focusable property of your edittext to "false" and you are done.



                              <EditText
                              android:id="@+id/EditTextInput"
                              android:layout_width="fill_parent"
                              android:layout_height="wrap_content"
                              android:focusable="false"
                              android:gravity="right"
                              android:cursorVisible="true">
                              </EditText>


                              Below options doesn't work



                              In code:



                              editText.setEnabled(false);
                              Or, in XML:
                              android:editable="false"







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 27 '14 at 5:49

























                              answered Nov 25 '14 at 11:31









                              ramit girdhar

                              1,3581622




                              1,3581622






















                                  up vote
                                  8
                                  down vote













                                  You can try the following method :



                                   private void disableEditText(EditText editText) {
                                  editText.setFocusable(false);
                                  editText.setEnabled(false);
                                  editText.setCursorVisible(false);
                                  editText.setKeyListener(null);
                                  editText.setBackgroundColor(Color.TRANSPARENT);
                                  }


                                  Enabled EditText :



                                  Enabled EditText



                                  Disabled EditText :



                                  Disabled EditText



                                  It works for me and hope it helps you.






                                  share|improve this answer























                                  • good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null);
                                    – Syed Raza Mehdi
                                    Aug 30 '16 at 9:45















                                  up vote
                                  8
                                  down vote













                                  You can try the following method :



                                   private void disableEditText(EditText editText) {
                                  editText.setFocusable(false);
                                  editText.setEnabled(false);
                                  editText.setCursorVisible(false);
                                  editText.setKeyListener(null);
                                  editText.setBackgroundColor(Color.TRANSPARENT);
                                  }


                                  Enabled EditText :



                                  Enabled EditText



                                  Disabled EditText :



                                  Disabled EditText



                                  It works for me and hope it helps you.






                                  share|improve this answer























                                  • good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null);
                                    – Syed Raza Mehdi
                                    Aug 30 '16 at 9:45













                                  up vote
                                  8
                                  down vote










                                  up vote
                                  8
                                  down vote









                                  You can try the following method :



                                   private void disableEditText(EditText editText) {
                                  editText.setFocusable(false);
                                  editText.setEnabled(false);
                                  editText.setCursorVisible(false);
                                  editText.setKeyListener(null);
                                  editText.setBackgroundColor(Color.TRANSPARENT);
                                  }


                                  Enabled EditText :



                                  Enabled EditText



                                  Disabled EditText :



                                  Disabled EditText



                                  It works for me and hope it helps you.






                                  share|improve this answer














                                  You can try the following method :



                                   private void disableEditText(EditText editText) {
                                  editText.setFocusable(false);
                                  editText.setEnabled(false);
                                  editText.setCursorVisible(false);
                                  editText.setKeyListener(null);
                                  editText.setBackgroundColor(Color.TRANSPARENT);
                                  }


                                  Enabled EditText :



                                  Enabled EditText



                                  Disabled EditText :



                                  Disabled EditText



                                  It works for me and hope it helps you.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Apr 3 '15 at 14:51

























                                  answered Apr 3 '15 at 14:19









                                  Maksym Kalin

                                  1,1431315




                                  1,1431315












                                  • good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null);
                                    – Syed Raza Mehdi
                                    Aug 30 '16 at 9:45


















                                  • good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null);
                                    – Syed Raza Mehdi
                                    Aug 30 '16 at 9:45
















                                  good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null);
                                  – Syed Raza Mehdi
                                  Aug 30 '16 at 9:45




                                  good answer but it can be improved by removing the line in which the background color is being change and add editText.setKeyListener(null);
                                  – Syed Raza Mehdi
                                  Aug 30 '16 at 9:45










                                  up vote
                                  4
                                  down vote













                                  Edittext edittext = (EditText)findViewById(R.id.edit);
                                  edittext.setEnabled(false);





                                  share|improve this answer

























                                    up vote
                                    4
                                    down vote













                                    Edittext edittext = (EditText)findViewById(R.id.edit);
                                    edittext.setEnabled(false);





                                    share|improve this answer























                                      up vote
                                      4
                                      down vote










                                      up vote
                                      4
                                      down vote









                                      Edittext edittext = (EditText)findViewById(R.id.edit);
                                      edittext.setEnabled(false);





                                      share|improve this answer












                                      Edittext edittext = (EditText)findViewById(R.id.edit);
                                      edittext.setEnabled(false);






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Apr 10 '17 at 11:29









                                      saigopi

                                      3,1562221




                                      3,1562221






















                                          up vote
                                          2
                                          down vote













                                          The below code disables the EditText in android



                                          editText.setEnabled(false);





                                          share|improve this answer























                                          • just set focusable property of your edittext to "false" and you are done. <!-- begin snippet: js hide: false --> <!-- language: lang-html --> <EditText android:id="@+id/EditTextInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:gravity="right" android:cursorVisible="true"> </EditText> <!-- end snippet -->
                                            – ramit girdhar
                                            Nov 25 '14 at 11:26

















                                          up vote
                                          2
                                          down vote













                                          The below code disables the EditText in android



                                          editText.setEnabled(false);





                                          share|improve this answer























                                          • just set focusable property of your edittext to "false" and you are done. <!-- begin snippet: js hide: false --> <!-- language: lang-html --> <EditText android:id="@+id/EditTextInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:gravity="right" android:cursorVisible="true"> </EditText> <!-- end snippet -->
                                            – ramit girdhar
                                            Nov 25 '14 at 11:26















                                          up vote
                                          2
                                          down vote










                                          up vote
                                          2
                                          down vote









                                          The below code disables the EditText in android



                                          editText.setEnabled(false);





                                          share|improve this answer














                                          The below code disables the EditText in android



                                          editText.setEnabled(false);






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited May 4 '11 at 21:13









                                          GSerg

                                          58.4k14100216




                                          58.4k14100216










                                          answered May 4 '11 at 6:38









                                          uday

                                          6253915




                                          6253915












                                          • just set focusable property of your edittext to "false" and you are done. <!-- begin snippet: js hide: false --> <!-- language: lang-html --> <EditText android:id="@+id/EditTextInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:gravity="right" android:cursorVisible="true"> </EditText> <!-- end snippet -->
                                            – ramit girdhar
                                            Nov 25 '14 at 11:26




















                                          • just set focusable property of your edittext to "false" and you are done. <!-- begin snippet: js hide: false --> <!-- language: lang-html --> <EditText android:id="@+id/EditTextInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:gravity="right" android:cursorVisible="true"> </EditText> <!-- end snippet -->
                                            – ramit girdhar
                                            Nov 25 '14 at 11:26


















                                          just set focusable property of your edittext to "false" and you are done. <!-- begin snippet: js hide: false --> <!-- language: lang-html --> <EditText android:id="@+id/EditTextInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:gravity="right" android:cursorVisible="true"> </EditText> <!-- end snippet -->
                                          – ramit girdhar
                                          Nov 25 '14 at 11:26






                                          just set focusable property of your edittext to "false" and you are done. <!-- begin snippet: js hide: false --> <!-- language: lang-html --> <EditText android:id="@+id/EditTextInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusable="false" android:gravity="right" android:cursorVisible="true"> </EditText> <!-- end snippet -->
                                          – ramit girdhar
                                          Nov 25 '14 at 11:26












                                          up vote
                                          2
                                          down vote













                                          edittext.setFocusable(false); 
                                          edittext.setEnabled(false);

                                          InputMethodManager imm = (InputMethodManager)
                                          getSystemService(Context.INPUT_METHOD_SERVICE);

                                          imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
                                          //removes on screen keyboard





                                          share|improve this answer



























                                            up vote
                                            2
                                            down vote













                                            edittext.setFocusable(false); 
                                            edittext.setEnabled(false);

                                            InputMethodManager imm = (InputMethodManager)
                                            getSystemService(Context.INPUT_METHOD_SERVICE);

                                            imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
                                            //removes on screen keyboard





                                            share|improve this answer

























                                              up vote
                                              2
                                              down vote










                                              up vote
                                              2
                                              down vote









                                              edittext.setFocusable(false); 
                                              edittext.setEnabled(false);

                                              InputMethodManager imm = (InputMethodManager)
                                              getSystemService(Context.INPUT_METHOD_SERVICE);

                                              imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
                                              //removes on screen keyboard





                                              share|improve this answer














                                              edittext.setFocusable(false); 
                                              edittext.setEnabled(false);

                                              InputMethodManager imm = (InputMethodManager)
                                              getSystemService(Context.INPUT_METHOD_SERVICE);

                                              imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
                                              //removes on screen keyboard






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Apr 1 '12 at 23:17









                                              dldnh

                                              8,47432747




                                              8,47432747










                                              answered Apr 1 '12 at 21:39









                                              Kumar Sukhani

                                              32827




                                              32827






















                                                  up vote
                                                  1
                                                  down vote













                                                  To disable a edittext in android:



                                                  editText.setEnabled(false);





                                                  share|improve this answer























                                                  • not working in some devices with version < 2.3.
                                                    – Ketan Ahir
                                                    Dec 10 '13 at 9:10

















                                                  up vote
                                                  1
                                                  down vote













                                                  To disable a edittext in android:



                                                  editText.setEnabled(false);





                                                  share|improve this answer























                                                  • not working in some devices with version < 2.3.
                                                    – Ketan Ahir
                                                    Dec 10 '13 at 9:10















                                                  up vote
                                                  1
                                                  down vote










                                                  up vote
                                                  1
                                                  down vote









                                                  To disable a edittext in android:



                                                  editText.setEnabled(false);





                                                  share|improve this answer














                                                  To disable a edittext in android:



                                                  editText.setEnabled(false);






                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited May 4 '11 at 21:13









                                                  GSerg

                                                  58.4k14100216




                                                  58.4k14100216










                                                  answered May 4 '11 at 6:16









                                                  Vineet

                                                  812




                                                  812












                                                  • not working in some devices with version < 2.3.
                                                    – Ketan Ahir
                                                    Dec 10 '13 at 9:10




















                                                  • not working in some devices with version < 2.3.
                                                    – Ketan Ahir
                                                    Dec 10 '13 at 9:10


















                                                  not working in some devices with version < 2.3.
                                                  – Ketan Ahir
                                                  Dec 10 '13 at 9:10






                                                  not working in some devices with version < 2.3.
                                                  – Ketan Ahir
                                                  Dec 10 '13 at 9:10












                                                  up vote
                                                  1
                                                  down vote













                                                  You can write edittext.setInputType(0) if you want to show the edittext but not input any values






                                                  share|improve this answer



























                                                    up vote
                                                    1
                                                    down vote













                                                    You can write edittext.setInputType(0) if you want to show the edittext but not input any values






                                                    share|improve this answer

























                                                      up vote
                                                      1
                                                      down vote










                                                      up vote
                                                      1
                                                      down vote









                                                      You can write edittext.setInputType(0) if you want to show the edittext but not input any values






                                                      share|improve this answer














                                                      You can write edittext.setInputType(0) if you want to show the edittext but not input any values







                                                      share|improve this answer














                                                      share|improve this answer



                                                      share|improve this answer








                                                      edited May 4 '11 at 21:14









                                                      GSerg

                                                      58.4k14100216




                                                      58.4k14100216










                                                      answered May 4 '11 at 6:35









                                                      Jaydeep Khamar

                                                      5,48032630




                                                      5,48032630






















                                                          up vote
                                                          0
                                                          down vote













                                                          Write this in parent:



                                                          android:descendantFocusability="beforeDescendants"
                                                          android:focusableInTouchMode="true"


                                                          Example:



                                                          <RelativeLayout 
                                                          android:id="@+id/menu_2_zawezanie_rl"
                                                          android:layout_width="match_parent"
                                                          android:layout_height="wrap_content"
                                                          android:layout_below="@+id/menu_2_horizontalScrollView"
                                                          android:descendantFocusability="beforeDescendants"
                                                          android:focusableInTouchMode="true"
                                                          android:orientation="horizontal"
                                                          android:background="@drawable/rame">

                                                          <EditText
                                                          android:id="@+id/menu2_et"
                                                          android:layout_width="wrap_content"
                                                          android:layout_height="wrap_content"
                                                          android:layout_alignParentLeft="true"
                                                          android:layout_centerVertical="true"
                                                          android:layout_toLeftOf="@+id/menu2_ibtn"
                                                          android:gravity="center"
                                                          android:hint="@string/filtruj" >
                                                          </EditText>
                                                          <ImageButton
                                                          android:id="@+id/menu2_ibtn"
                                                          android:layout_width="wrap_content"
                                                          android:layout_height="wrap_content"
                                                          android:layout_alignParentLeft="true"
                                                          android:layout_centerVertical="true"
                                                          android:background="@null"
                                                          android:src="@drawable/selector_btn" />







                                                          share|improve this answer



























                                                            up vote
                                                            0
                                                            down vote













                                                            Write this in parent:



                                                            android:descendantFocusability="beforeDescendants"
                                                            android:focusableInTouchMode="true"


                                                            Example:



                                                            <RelativeLayout 
                                                            android:id="@+id/menu_2_zawezanie_rl"
                                                            android:layout_width="match_parent"
                                                            android:layout_height="wrap_content"
                                                            android:layout_below="@+id/menu_2_horizontalScrollView"
                                                            android:descendantFocusability="beforeDescendants"
                                                            android:focusableInTouchMode="true"
                                                            android:orientation="horizontal"
                                                            android:background="@drawable/rame">

                                                            <EditText
                                                            android:id="@+id/menu2_et"
                                                            android:layout_width="wrap_content"
                                                            android:layout_height="wrap_content"
                                                            android:layout_alignParentLeft="true"
                                                            android:layout_centerVertical="true"
                                                            android:layout_toLeftOf="@+id/menu2_ibtn"
                                                            android:gravity="center"
                                                            android:hint="@string/filtruj" >
                                                            </EditText>
                                                            <ImageButton
                                                            android:id="@+id/menu2_ibtn"
                                                            android:layout_width="wrap_content"
                                                            android:layout_height="wrap_content"
                                                            android:layout_alignParentLeft="true"
                                                            android:layout_centerVertical="true"
                                                            android:background="@null"
                                                            android:src="@drawable/selector_btn" />







                                                            share|improve this answer

























                                                              up vote
                                                              0
                                                              down vote










                                                              up vote
                                                              0
                                                              down vote









                                                              Write this in parent:



                                                              android:descendantFocusability="beforeDescendants"
                                                              android:focusableInTouchMode="true"


                                                              Example:



                                                              <RelativeLayout 
                                                              android:id="@+id/menu_2_zawezanie_rl"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content"
                                                              android:layout_below="@+id/menu_2_horizontalScrollView"
                                                              android:descendantFocusability="beforeDescendants"
                                                              android:focusableInTouchMode="true"
                                                              android:orientation="horizontal"
                                                              android:background="@drawable/rame">

                                                              <EditText
                                                              android:id="@+id/menu2_et"
                                                              android:layout_width="wrap_content"
                                                              android:layout_height="wrap_content"
                                                              android:layout_alignParentLeft="true"
                                                              android:layout_centerVertical="true"
                                                              android:layout_toLeftOf="@+id/menu2_ibtn"
                                                              android:gravity="center"
                                                              android:hint="@string/filtruj" >
                                                              </EditText>
                                                              <ImageButton
                                                              android:id="@+id/menu2_ibtn"
                                                              android:layout_width="wrap_content"
                                                              android:layout_height="wrap_content"
                                                              android:layout_alignParentLeft="true"
                                                              android:layout_centerVertical="true"
                                                              android:background="@null"
                                                              android:src="@drawable/selector_btn" />







                                                              share|improve this answer














                                                              Write this in parent:



                                                              android:descendantFocusability="beforeDescendants"
                                                              android:focusableInTouchMode="true"


                                                              Example:



                                                              <RelativeLayout 
                                                              android:id="@+id/menu_2_zawezanie_rl"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content"
                                                              android:layout_below="@+id/menu_2_horizontalScrollView"
                                                              android:descendantFocusability="beforeDescendants"
                                                              android:focusableInTouchMode="true"
                                                              android:orientation="horizontal"
                                                              android:background="@drawable/rame">

                                                              <EditText
                                                              android:id="@+id/menu2_et"
                                                              android:layout_width="wrap_content"
                                                              android:layout_height="wrap_content"
                                                              android:layout_alignParentLeft="true"
                                                              android:layout_centerVertical="true"
                                                              android:layout_toLeftOf="@+id/menu2_ibtn"
                                                              android:gravity="center"
                                                              android:hint="@string/filtruj" >
                                                              </EditText>
                                                              <ImageButton
                                                              android:id="@+id/menu2_ibtn"
                                                              android:layout_width="wrap_content"
                                                              android:layout_height="wrap_content"
                                                              android:layout_alignParentLeft="true"
                                                              android:layout_centerVertical="true"
                                                              android:background="@null"
                                                              android:src="@drawable/selector_btn" />








                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Dec 2 '13 at 5:55

























                                                              answered Dec 2 '13 at 3:30









                                                              Gimer

                                                              135




                                                              135






















                                                                  up vote
                                                                  0
                                                                  down vote













                                                                  According to me...if you have already declared the edittext in the XML file and set the property in the XML file "android:enabled=false" and disable at runtime to it at that time in java file adding only 2 or 3 lines




                                                                  1. First create the object

                                                                  2. Declare EditText et1;


                                                                  3. Get by id



                                                                    et1 = (EditText) FindViewById(R.id.edittext1);
                                                                    et1.setEnabled(false);




                                                                  You can do enable or disable to every control at run time by java file and design time by XML file.






                                                                  share|improve this answer



























                                                                    up vote
                                                                    0
                                                                    down vote













                                                                    According to me...if you have already declared the edittext in the XML file and set the property in the XML file "android:enabled=false" and disable at runtime to it at that time in java file adding only 2 or 3 lines




                                                                    1. First create the object

                                                                    2. Declare EditText et1;


                                                                    3. Get by id



                                                                      et1 = (EditText) FindViewById(R.id.edittext1);
                                                                      et1.setEnabled(false);




                                                                    You can do enable or disable to every control at run time by java file and design time by XML file.






                                                                    share|improve this answer

























                                                                      up vote
                                                                      0
                                                                      down vote










                                                                      up vote
                                                                      0
                                                                      down vote









                                                                      According to me...if you have already declared the edittext in the XML file and set the property in the XML file "android:enabled=false" and disable at runtime to it at that time in java file adding only 2 or 3 lines




                                                                      1. First create the object

                                                                      2. Declare EditText et1;


                                                                      3. Get by id



                                                                        et1 = (EditText) FindViewById(R.id.edittext1);
                                                                        et1.setEnabled(false);




                                                                      You can do enable or disable to every control at run time by java file and design time by XML file.






                                                                      share|improve this answer














                                                                      According to me...if you have already declared the edittext in the XML file and set the property in the XML file "android:enabled=false" and disable at runtime to it at that time in java file adding only 2 or 3 lines




                                                                      1. First create the object

                                                                      2. Declare EditText et1;


                                                                      3. Get by id



                                                                        et1 = (EditText) FindViewById(R.id.edittext1);
                                                                        et1.setEnabled(false);




                                                                      You can do enable or disable to every control at run time by java file and design time by XML file.







                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Jul 9 '14 at 9:30









                                                                      ann

                                                                      5881919




                                                                      5881919










                                                                      answered Feb 23 '14 at 18:52









                                                                      Nimisha Patel

                                                                      112




                                                                      112






















                                                                          up vote
                                                                          0
                                                                          down vote













                                                                          Enable:



                                                                          private void enableEditText() {
                                                                          mEditText.setFocusableInTouchMode(true);
                                                                          mEditText.setFocusable(true);
                                                                          mEditText.setEnabled(true);
                                                                          }


                                                                          Disable:



                                                                          private void disableEditText() {
                                                                          mEditText.setEnabled(false);
                                                                          mEditText.setFocusable(false);
                                                                          mEditText.setFocusableInTouchMode(false);
                                                                          }





                                                                          share|improve this answer

























                                                                            up vote
                                                                            0
                                                                            down vote













                                                                            Enable:



                                                                            private void enableEditText() {
                                                                            mEditText.setFocusableInTouchMode(true);
                                                                            mEditText.setFocusable(true);
                                                                            mEditText.setEnabled(true);
                                                                            }


                                                                            Disable:



                                                                            private void disableEditText() {
                                                                            mEditText.setEnabled(false);
                                                                            mEditText.setFocusable(false);
                                                                            mEditText.setFocusableInTouchMode(false);
                                                                            }





                                                                            share|improve this answer























                                                                              up vote
                                                                              0
                                                                              down vote










                                                                              up vote
                                                                              0
                                                                              down vote









                                                                              Enable:



                                                                              private void enableEditText() {
                                                                              mEditText.setFocusableInTouchMode(true);
                                                                              mEditText.setFocusable(true);
                                                                              mEditText.setEnabled(true);
                                                                              }


                                                                              Disable:



                                                                              private void disableEditText() {
                                                                              mEditText.setEnabled(false);
                                                                              mEditText.setFocusable(false);
                                                                              mEditText.setFocusableInTouchMode(false);
                                                                              }





                                                                              share|improve this answer












                                                                              Enable:



                                                                              private void enableEditText() {
                                                                              mEditText.setFocusableInTouchMode(true);
                                                                              mEditText.setFocusable(true);
                                                                              mEditText.setEnabled(true);
                                                                              }


                                                                              Disable:



                                                                              private void disableEditText() {
                                                                              mEditText.setEnabled(false);
                                                                              mEditText.setFocusable(false);
                                                                              mEditText.setFocusableInTouchMode(false);
                                                                              }






                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Oct 10 at 10:21









                                                                              Danylo Volokh

                                                                              2,13412030




                                                                              2,13412030






























                                                                                  draft saved

                                                                                  draft discarded




















































                                                                                  Thanks for contributing an answer to Stack Overflow!


                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                  But avoid



                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                  To learn more, see our tips on writing great answers.





                                                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                  Please pay close attention to the following guidance:


                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                  But avoid



                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                  To learn more, see our tips on writing great answers.




                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function () {
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5879250%2fhow-to-disable-edittext-in-android%23new-answer', 'question_page');
                                                                                  }
                                                                                  );

                                                                                  Post as a guest















                                                                                  Required, but never shown





















































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown

































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown







                                                                                  Popular posts from this blog

                                                                                  Xamarin.iOS Cant Deploy on Iphone

                                                                                  Glorious Revolution

                                                                                  Dulmage-Mendelsohn matrix decomposition in Python