Пример #1
0
  /**
   * add new tab with title text
   *
   * @param title title text
   */
  public void addTab(CharSequence title) {
    int layoutId = getLayoutId(type);
    TextView tv = (TextView) inflater.inflate(layoutId, tabWidget, false);
    tv.setText(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      // tv.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple);

    } else {
      // create background using colorControlActivated
      StateListDrawable d = new StateListDrawable();
      d.addState(
          new int[] {android.R.attr.state_pressed}, new ColorDrawable(colorControlActivated));
      d.setAlpha(180);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        tv.setBackgroundDrawable(d);
      } else {
        tv.setBackgroundDrawable(d);
      }
    }

    int tabId = tabWidget.getTabCount();

    addTab(newTabSpec(String.valueOf(tabId)).setIndicator(tv).setContent(android.R.id.tabcontent));
  }
  public void setBackgroundDrawable(KrollDict d, Drawable drawable) {
    StateListDrawable stateDrawable = new StateListDrawable();

    // use transparent highlight so the selector drawable is visible over background
    ColorDrawable transparent = new ColorDrawable(Color.TRANSPARENT);
    stateDrawable.addState(
        new int[] {
          android.R.attr.state_window_focused,
          android.R.attr.state_enabled,
          android.R.attr.state_pressed
        },
        transparent);
    stateDrawable.addState(new int[] {android.R.attr.state_selected}, transparent);

    stateDrawable.addState(
        new int[] {
          android.R.attr.state_focused,
          android.R.attr.state_window_focused,
          android.R.attr.state_enabled
        },
        drawable);
    stateDrawable.addState(new int[0], drawable);

    if (d.containsKey(TiC.PROPERTY_OPACITY)) {
      stateDrawable.setAlpha(Math.round(TiConvert.toFloat(d, TiC.PROPERTY_OPACITY) * 255));
    }
    setBackgroundDrawable(stateDrawable);
  }
Пример #3
0
  /**
   * add new tab with specified view
   *
   * @param view tab view
   */
  public void addTab(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      // view.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple);

    } else {
      // create background using colorControlActivated
      StateListDrawable d = new StateListDrawable();
      d.addState(
          new int[] {android.R.attr.state_pressed}, new ColorDrawable(colorControlActivated));
      d.setAlpha(180);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackgroundDrawable(d);
      } else {
        view.setBackgroundDrawable(d);
      }
    }

    int tabId = tabWidget.getTabCount();

    addTab(
        newTabSpec(String.valueOf(tabId)).setIndicator(view).setContent(android.R.id.tabcontent));
  }