Only show number buttons on Soft Keyboard in Android?

前端 未结 8 1410
栀梦
栀梦 2020-12-01 10:06

On the soft keyboard in Android you can set the soft keyboard to show the numbers instead of a-z keyboard using android:inputType=\"numberDecimal\". However, wh

相关标签:
8条回答
  • 2020-12-01 10:58

    I had implemented this for android in Xamarin. So, my code is in C#. But the principal stays the same. You can set attribute of edittext to android:inputType="numberPassword".

    Then within your code you attach custom transformation method to your edittext view.

    holder.edtxtQty.TransformationMethod = new HiddenPasswordTransformationMethod();
    
    private class HiddenPasswordTransformationMethod : global::Android.Text.Method.PasswordTransformationMethod
            {
                public override Java.Lang.ICharSequence GetTransformationFormatted(Java.Lang.ICharSequence source, View view)
                {
                    return new PasswordCharSequence(source);
                }
            }
    
        private class PasswordCharSequence : Java.Lang.Object, Java.Lang.ICharSequence
        {
            private char DOT = '\u2022';
    
            private Java.Lang.ICharSequence _source;
            public PasswordCharSequence(Java.Lang.ICharSequence source)
            {
                _source = source;
            }
    
            public char CharAt(int index)
            {
                return _source.CharAt(index);
            }
    
            public int Length()
            {
                return _source.Length();
            }
    
            public Java.Lang.ICharSequence SubSequenceFormatted(int start, int end)
            {
                return _source.SubSequenceFormatted(start, end); // Return default
            }
    
            public IEnumerator<char> GetEnumerator()
            {
                return _source.GetEnumerator();
            }
    
            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return _source.GetEnumerator();
            }
        }
    
    0 讨论(0)
  • 2020-12-01 11:02

    The phone number pad is the closest thing I've found (set inputType="phone" on your EditText).

    0 讨论(0)
提交回复
热议问题