Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by moghes · Jun 21, 2018 at 04:20 PM · keyboardinputfieldnative plugin

Native keyboard height and hide the input field

Hello everyone,

Its just a pain to get the native keyboard height in unity and then hide the native input field. Hiding the input field work fine on ios and never on android.

For Getting the keyboard height I have searched and came out with several solutions which never worked.

For android none of the below worked for me. printing them result in 0.

1-

 TouchScreenKeyboard.area.height

2-

 TouchScreenKeyboard.area.max.y

3 -

 public int GetAndroidKeyboardSize()
         {        
             using(AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
             {
                 AndroidJavaObject View = UnityClass.GetStatic<AndroidJavaObject>("currentActivity").Get<AndroidJavaObject>("mUnityPlayer").Call<AndroidJavaObject>("getView");
     
                 using(AndroidJavaObject Rct = new AndroidJavaObject("android.graphics.Rect"))
                 {
                     View.Call("getWindowVisibleDisplayFrame", Rct);
                     return Screen.height - Rct.Call<int>("height");
                 }
             }
         }

4 -

 private float GetKeyboardHeightRatio() 
         {
             #if UNITY_ANDROID        
             using (AndroidJavaClass UnityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
                 AndroidJavaObject View = UnityClass.GetStatic<AndroidJavaObject>("currentActivity").Get<AndroidJavaObject>("mUnityPlayer").Call<AndroidJavaObject>("getView");
                 using (AndroidJavaObject rect = new AndroidJavaObject("android.graphics.Rect")) {
                     View.Call("getWindowVisibleDisplayFrame", rect);
                     return (float)(Screen.height - rect.Call<int>("height")) / Screen.height;
                 }
             }
             #else
             return (float)TouchScreenKeyboard.area.height / Screen.height;
             #endif
         }

Similarly no success on ios with methods 1&2 since 3&4 are only for android.

Temporarily I used a static size as the keyboard size (40% of canvas size) and the UI scaling works but just can't get the value of the soft native keyboard.

And now want to hide the native input field, this time the trouble is only in android.

TouchScreenKeyboard.hideInput = true; ------ doesn't work this.GetComponent ().shouldHideMobileInput = true; ---- doesn't work

Now before thinking of a plugin just to get a size or hiding the input field, let me know if someone has the simpler solution.

If we need a native plugin for this ... too bad to unity.

Any help or useful links are appreciated. btw I think I've checked all possible links, please suggest a method you've tried and worked for you.

I am using Unity 2017.3.1

thanks in advance

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by shweta-unity · Aug 04, 2020 at 09:19 AM

Hi @moghes, I know this is an old question, but did you get any solution to this? I am also stuck with the issue.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Nikel_MIF · Nov 14, 2020 at 09:08 PM

@moghes

 TouchScreenKeyboard.area

Always return zero for Android - it`s written in the manual.

As far as I know code samples, which call native Android to get keyboard height will be work just when keyboard will be opened fully, you should await several seconds, before call this methods or use coroutines and with help yeild return new WaitUntil(predicate <bool>) wait until result will be non-zero, but I can`t say, that it`s best solution.

About inputfield - can`t remember any solutions at the Unity side, if I find any code snippets related to this question - I`ll write here.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

88 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Force UI Input Field Character limit with C Sharp 0 Answers

password inputfield on iOS- keyboard type 0 Answers

[iOS] Sliding input field/keyboard question 0 Answers

InputField not updating 0 Answers

Need help installing plugin: Razer Chroma SDK Plugin Colore 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges