【问题标题】:Android Tab Layout with View Pager带有 View Pager 的 Android 选项卡布局
【发布时间】:2016-07-25 03:49:22
【问题描述】:

我正在使用包含 4 个选项卡的视图寻呼机的选项卡布局,我的问题是,如何在选项卡上设置 onLongClickListener 然后重命名它? 提前致谢!

【问题讨论】:

    标签: android


    【解决方案1】:
    try like this.
    
     private void changeTabsText() {
    
        ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
        int tabsCount = vg.getChildCount();
        for (int j = 0; j < tabsCount; j++) {
            ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
            int tabChildsCount = vgTab.getChildCount();
            for (int i = 0; i < tabChildsCount; i++) {
                View tabViewChild = vgTab.getChildAt(i);
                if (tabViewChild instanceof TextView) {
                    ((TextView) tabViewChild).setText("your Text");
                }
            }
        }
    } 
    

    【讨论】:

      【解决方案2】:

      onLongClickListener

      View tabView= mTabHost.getTabWidget().getChildAt(i);
      // set the tag information at the view of the tab (the tag contains the position number of the tab)
      tabView.setTag( Integer.valueOf(i));
      tabView.setOnLongClickListener(new OnLongClickListener() {
      
                  @Override
                  public boolean onLongClick(View v) {
                      // TODO Auto-generated method stub
                      // I print the number position of the tab
                      Log.d("tab number", ((Integer)view.getTag()).toString() );
                      return false;
                  }
              });
      

      重命名标签

      ((TextView)((RelativeLayout)getTabWidget().getChildAt(tabIndex)).getChildAt(textIndex)).setText("NewTabText");
      

      【讨论】:

      • 请试一试。我希望它能工作或分享您的代码,以便我可以尝试正确修复它。谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多