How to force an entry Numeric on android work with comma instead of point to decimal numbers?

Asked

Viewed 917 times

2

I tried to use Culture but it didn’t work either and I didn’t want to do the trick of putting a replace before sending it to the base. Even with the Xlab I could put the keyboard to work ptbr and let put comma instead of point. Someone has some more luxurious solution ?

  • The entrance is via prompt dialog? Uses XAML or UI code?

  • is direct by entry by code and not XAML.

1 answer

1

I found a solution in forum of Xamarin (source code is at the end of the reply)

You should create a custom keyboard layout (resource XML). This code below is already customized for your need:

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="33%p" android:horizontalGap="0px"
    android:verticalGap="0px" android:keyHeight="54dip">

    <Row>
        <Key android:codes="8" android:keyLabel="1" android:keyEdgeFlags="left" />
        <Key android:codes="9" android:keyLabel="2" />
        <Key android:codes="10" android:keyLabel="3" android:keyEdgeFlags="right" />
    </Row>

    <Row>
        <Key android:codes="11" android:keyLabel="4" android:keyEdgeFlags="left" />
        <Key android:codes="12" android:keyLabel="5" />
        <Key android:codes="13" android:keyLabel="6" android:keyEdgeFlags="right" />
    </Row>

    <Row>
        <Key android:codes="14" android:keyLabel="7" android:keyEdgeFlags="left" />
        <Key android:codes="15" android:keyLabel="8" />
        <Key android:codes="16" android:keyLabel="9" android:keyEdgeFlags="right" />
    </Row>

    <Row>
        <Key android:codes="67" android:keyIcon="@drawable/sym_keyboard_delete"
            android:iconPreview="@drawable/sym_keyboard_delete"
            android:keyEdgeFlags="left" />
    <Key android:codes="55" android:keyLabel="," />
        <Key android:codes="7" android:keyLabel="0" />
        <Key android:codes="66" android:keyEdgeFlags="right"
            android:keyIcon="@drawable/sym_keyboard_feedback_return"
            android:iconPreview="@drawable/sym_keyboard_feedback_return" />
    </Row>

</Keyboard>

Using the custom keyboard:

public class Activity1 : Activity
{
    public CustomKeyboardView mKeyboardView;
    public View mTargetView;
    public Keyboard mKeyboard;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        mKeyboard = new Keyboard(this, Resource.Xml.keyboard2);
        mTargetView = (EditText)FindViewById(Resource.Id.target);

        mKeyboardView = (CustomKeyboardView)FindViewById(Resource.Id.keyboard_view);
        mKeyboardView.Keyboard = mKeyboard;

        mTargetView.Touch += (sender, e) => {
            Log.Info("onTouch", "true");
            ShowKeyboardWithAnimation();
            e.Handled = true;
        };

        mKeyboardView.Key += (sender, e) => {
            long eventTime = JavaSystem.CurrentTimeMillis();
            KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.KeepTouchMode);

            this.DispatchKeyEvent(ev);
        };
    }

    public void ShowKeyboardWithAnimation()
    {
        Log.Info("keyboardState", mKeyboardView.Visibility.ToString());
        if (mKeyboardView.Visibility == ViewStates.Gone)
        {
            Animation animation = AnimationUtils.LoadAnimation(
                this,
                Resource.Animation.slide_in_bottom
            );
            mKeyboardView.ShowWithAnimation(animation);
        }
    }
}

inserir a descrição da imagem aqui

Use this android code table for customization: Keyevent

Source code: Customkeyboard.zip

Browser other questions tagged

You are not signed in. Login or sign up in order to post.