<bdo id='zHVpV'></bdo><ul id='zHVpV'></ul>
      <tfoot id='zHVpV'></tfoot>
    1. <small id='zHVpV'></small><noframes id='zHVpV'>

        <i id='zHVpV'><tr id='zHVpV'><dt id='zHVpV'><q id='zHVpV'><span id='zHVpV'><b id='zHVpV'><form id='zHVpV'><ins id='zHVpV'></ins><ul id='zHVpV'></ul><sub id='zHVpV'></sub></form><legend id='zHVpV'></legend><bdo id='zHVpV'><pre id='zHVpV'><center id='zHVpV'></center></pre></bdo></b><th id='zHVpV'></th></span></q></dt></tr></i><div id='zHVpV'><tfoot id='zHVpV'></tfoot><dl id='zHVpV'><fieldset id='zHVpV'></fieldset></dl></div>

        <legend id='zHVpV'><style id='zHVpV'><dir id='zHVpV'><q id='zHVpV'></q></dir></style></legend>

        我不能在 androidx.appcompat:appcompat:1.1.0 上使用 API 反射

        时间:2024-04-14

        <tfoot id='a0mfu'></tfoot>

          • <bdo id='a0mfu'></bdo><ul id='a0mfu'></ul>
              <tbody id='a0mfu'></tbody>

              1. <i id='a0mfu'><tr id='a0mfu'><dt id='a0mfu'><q id='a0mfu'><span id='a0mfu'><b id='a0mfu'><form id='a0mfu'><ins id='a0mfu'></ins><ul id='a0mfu'></ul><sub id='a0mfu'></sub></form><legend id='a0mfu'></legend><bdo id='a0mfu'><pre id='a0mfu'><center id='a0mfu'></center></pre></bdo></b><th id='a0mfu'></th></span></q></dt></tr></i><div id='a0mfu'><tfoot id='a0mfu'></tfoot><dl id='a0mfu'><fieldset id='a0mfu'></fieldset></dl></div>

              2. <small id='a0mfu'></small><noframes id='a0mfu'>

                <legend id='a0mfu'><style id='a0mfu'><dir id='a0mfu'><q id='a0mfu'></q></dir></style></legend>
                • 本文介绍了我不能在 androidx.appcompat:appcompat:1.1.0 上使用 API 反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have a problem with androidx.appcompat:appcompat:1.1.0. It's a new problem because on androidx.appcompat:appcompat:1.0.2 it does not exist.

                  I have a code that uses reflection to get mPopup Field from the spinner and set its height. It works very well on appcompat:1.0.2 but not on androidx.appcomppat:appcompat:1.1.0.

                  The code is

                   private void setPopUp() {
                  
                          try {
                              Field popup = getPopupField();
                  
                              // Get private mPopup member variable and try cast to ListPopupWindow
                              final android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);
                  
                              // Set popupWindow height to max - 40dp
                              spinner.post(new Runnable() {
                                  @Override
                                  public void run() {
                                      Rect r = new Rect();
                                      spinner.getGlobalVisibleRect(r);
                                      int height = 200;
                                      popupWindow.setHeight(height);
                                  }
                              });
                          } catch (NoClassDefFoundError | ClassCastException | IllegalAccessException e) {
                              // silently fail...
                          }
                  
                  
                      }
                  
                      private static Field getPopupField () {
                          if (sPopupField == null) {
                              try {
                                  Field popup = Spinner.class.getDeclaredField("mPopup");
                                  popup.setAccessible(true);
                  
                                  sPopupField = popup;
                              } catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException e) {
                                  // silently fail...
                              }
                          }
                          return sPopupField;
                      }
                  
                  

                  I read about bugs on a new appcompatActivity from appcompat:1.1.0. However, I can't find a solution to my problem.

                  解决方案

                  Everybody.

                  I was able to do it.

                  First, i put the spinner on the activity with java code. "programatically".

                       public void initTest(){
                      spinner2 = new Spinner(this, Spinner.MODE_DROPDOWN);
                      spinner2.setAdapter(new ArrayAdapter(this, R.layout.spinner_item, datos));
                      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                          spinner2.setId(spinner2.generateViewId());
                      }
                  
                      ConstraintLayout parentLayout = (ConstraintLayout)findViewById(R.id.main_activity);
                      parentLayout.addView(spinner2, 0);
                  
                      ConstraintSet cs = new ConstraintSet();
                      cs.clone(parentLayout);
                      cs.setHorizontalBias(spinner2.getId(), 0.473F);
                      cs.setVerticalBias(spinner2.getId(), 0.484F);
                      cs.connect(spinner2.getId(), ConstraintSet.BOTTOM, parentLayout.getId(),ConstraintSet.BOTTOM);
                      cs.connect(spinner2.getId(), ConstraintSet.START, parentLayout.getId(),ConstraintSet.START);
                      cs.connect(spinner2.getId(), ConstraintSet.TOP, parentLayout.getId(),ConstraintSet.TOP);
                      cs.connect(spinner2.getId(), ConstraintSet.END, parentLayout.getId(),ConstraintSet.END);
                      // cs view id, else getId() returns -1
                  
                      // connect start and end point of views, in this case top of child to top of parent.
                      // ... similarly add other constraints
                      cs.applyTo(parentLayout);
                  
                  }  
                  

                  Then i call the code put at the beginning in my question.

                  I hope it works for many people, and to skip this error of the new version.

                  Regards.

                  这篇关于我不能在 androidx.appcompat:appcompat:1.1.0 上使用 API 反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在应用程序之外创建警报对话框? 下一篇:iOS 应用程序可以为电话弹出警报定制设计吗?

                  相关文章

                  <tfoot id='x9FHh'></tfoot>

                  <small id='x9FHh'></small><noframes id='x9FHh'>

                    1. <legend id='x9FHh'><style id='x9FHh'><dir id='x9FHh'><q id='x9FHh'></q></dir></style></legend>
                        <bdo id='x9FHh'></bdo><ul id='x9FHh'></ul>

                    2. <i id='x9FHh'><tr id='x9FHh'><dt id='x9FHh'><q id='x9FHh'><span id='x9FHh'><b id='x9FHh'><form id='x9FHh'><ins id='x9FHh'></ins><ul id='x9FHh'></ul><sub id='x9FHh'></sub></form><legend id='x9FHh'></legend><bdo id='x9FHh'><pre id='x9FHh'><center id='x9FHh'></center></pre></bdo></b><th id='x9FHh'></th></span></q></dt></tr></i><div id='x9FHh'><tfoot id='x9FHh'></tfoot><dl id='x9FHh'><fieldset id='x9FHh'></fieldset></dl></div>