Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 aidesigner · Jun 12, 2012 at 04:50 PM · androidpluginjava

Using Java Plugin to add an Android Edittext view

I believe I have a fundamental problem as I have worked on it for days.

Objective: Add a Android EditText View to the bottom of my UnityPlayer activity by creating a Java Plugin. I need to do this because I will be using Android IME (voice) functionality in conjunction with the edittext view.

Strategy (See Code Comments): I created a Unity Java plugin that is primiraly composed of the "addEditTextView" Method below. Then in unity I have a GUI button to call "addEditTextView" Method. As expected the EditText view shows up at the bottom of the screen when the button is touched.

Problem: When I touch the edittext view is gets covered by the softkeyboard instead of moving upward. Note the UnityActivity content added by unity does pan/move upward as expected.

Experiments:

  • create a standalone Android Eclipse project with a basic activity. I then implemented this exact function again and it worked (Edittext stayed just above the softkeyboard). This leads me to believe that the Unity Activity is different in some way than my experimental standalone basic activity.

  • made the EditText box really tall (ie. 200). The softkeyboard covered the bottom half, which showed it is visible but not moving.

  • tried centering the textedit with "CENTER_IN_PARENT" (below) to see if I could learn something. It worked in the standalone Android project, but the edittext remained at the top for the unity project. Why - This is really confusing?

Code:

 final Activity _unityActivity; // Assign to the UnityPlayerActivy in contructor
 final Context _context; // Assign to the Unity Context in consturctor

 public void addEditTextView()
 {   
  _unityActivity.runOnUiThread(new Runnable()
  {
    public void run()
    {
      // Create LayoutParams that will place EditText at bottom of parent RelativeLayout (ie. ALIGN_PARENT_BOTTOM)
      RelativeLayout.LayoutParams localLayoutParams;
      (localLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT)).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

      // When I try centering the view with this line the edittext view remains at the top.  This leads me
      // to believe I am missing a basic concept.
      //(localLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT)).addRule(RelativeLayout.CENTER_IN_PARENT);

      // Create a RelativeLayout View to insert into UnityActivity
      RelativeLayout localRelativeLayout = new RelativeLayout(_context);
      EditText voiceText = new EditText(_context);
      voiceText.setHeight(200);

      // Add localLayoutParams created above to voiceText
      ((EditText)voiceText).setLayoutParams(localLayoutParams);
      localRelativeLayout.addView((View)voiceText);

      // Create LayoutParams for the RelativeLayout
      ViewGroup.LayoutParams vlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      
     // Add the localRelativeLayout containing voiceText to the unityActivity View
      _unityActivity.getWindow().addContentView(localRelativeLayout, vlp);
    }
 });
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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Now that Unity 4.1.2 broke the Android plugin examples, what do you use to learn them? 1 Answer

Problem reading sensor plugin, event won't trigger 2 Answers

Unity 3D Java plugin issues 5 Answers

java android plugin worker thread ends up in Unity mainthread 1 Answer

UnityPlayerActivity vs. UnityPlayerNativeActivity 0 Answers


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