예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    TAG = "TabHost2";
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.tab2);

    addTabView(getString(R.string.view1), null, View1.class);
    addTabView(getString(R.string.view2), null, View2.class);

    // TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    TabHost tabHost = getTabHost();
    TabWidget tw = tabHost.getTabWidget();
    tw.setBackgroundResource(R.drawable.tab_bg);

    for (int i = 0, n = tw.getChildCount(); i < n; i++) {
      View view = (View) tw.getChildTabViewAt(i);
      view.setBackgroundResource(R.drawable.none);

      TextView tv = (TextView) view.findViewById(android.R.id.title);
      tv.setTextSize(10);
      tv.setGravity(Gravity.CENTER_HORIZONTAL);
      tv.setText("Label" + (i + 1));

      ImageView img = (ImageView) view.findViewById(android.R.id.icon);
      img.setBackgroundResource(R.drawable.none);
      img.setImageResource(R.drawable.tab_button);
    }

    tabHost.setOnTabChangedListener(this);
    onTabChanged(getString(R.string.view1));
  }
예제 #2
0
  static boolean updateButtonBar(Activity a, int highlight) {
    final TabWidget ll = (TabWidget) a.findViewById(R.id.buttonbar);
    boolean withtabs = false;
    Intent intent = a.getIntent();
    if (intent != null) {
      withtabs = intent.getBooleanExtra("withtabs", false);
    }

    if (highlight == 0 || !withtabs) {
      ll.setVisibility(View.GONE);
      return withtabs;
    } else if (withtabs) {
      ll.setVisibility(View.VISIBLE);
    }
    for (int i = ll.getChildCount() - 1; i >= 0; i--) {

      View v = ll.getChildAt(i);
      boolean isActive = (v.getId() == highlight);
      if (isActive) {
        ll.setCurrentTab(i);
        sActiveTabIndex = i;
      }
      v.setTag(i);
      v.setOnFocusChangeListener(
          new View.OnFocusChangeListener() {

            public void onFocusChange(View v, boolean hasFocus) {
              if (hasFocus) {
                for (int i = 0; i < ll.getTabCount(); i++) {
                  if (ll.getChildTabViewAt(i) == v) {
                    ll.setCurrentTab(i);
                    processTabClick(
                        (Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId());
                    break;
                  }
                }
              }
            }
          });

      v.setOnClickListener(
          new View.OnClickListener() {

            public void onClick(View v) {
              processTabClick(
                  (Activity) ll.getContext(), v, ll.getChildAt(sActiveTabIndex).getId());
            }
          });
    }
    return withtabs;
  }
예제 #3
0
파일: Main.java 프로젝트: catch/Gardening
 @Override
 public void onTabChanged(String tabId) {
   int tabID = Integer.valueOf(tabId);
   for (int i = 0; i < mTabWidget.getChildCount(); i++) {
     View view = mTabWidget.getChildAt(i);
     TextView title = (TextView) view.findViewById(R.id.main_activity_tab_text);
     if (tabID == i) {
       view.setBackgroundResource(R.drawable.number_bg_pressed);
       title.setTextColor(Color.rgb(255, 255, 255));
     } else {
       view.setBackgroundResource(R.drawable.number_bg);
       title.setTextColor(Color.rgb(0, 0, 0));
     }
   }
 }
예제 #4
0
  private void initTabHost(Bundle args) {
    mTabHost = (TabHost) v.findViewById(android.R.id.tabhost);
    mTabHost.setup();
    TabInfo tabInfo = null;

    // Create Child Tab1

    Personal.AddTab(
        this,
        this.mTabHost,
        this.mTabHost.newTabSpec("subtab1").setIndicator(createTabView(mContext, "登入")),
        (tabInfo = new TabInfo("Tab1", PersonalLogin.class, args)));
    this.mHashMapTabInfo.put(tabInfo.tag, tabInfo);

    // Create Child Tab2
    Personal.AddTab(
        this,
        this.mTabHost,
        this.mTabHost.newTabSpec("subtab2").setIndicator(createTabView(mContext, "悠遊卡登入")),
        (tabInfo = new TabInfo("Tab2", PersonalLoginEasyCard.class, args)));
    this.mHashMapTabInfo.put(tabInfo.tag, tabInfo);
    mTabHost.setCurrentTab(0);

    // Create Child Tab3
    Personal.AddTab(
        this,
        this.mTabHost,
        this.mTabHost.newTabSpec("subtab3").setIndicator(createTabView(mContext, "註冊")),
        (tabInfo = new TabInfo("Tab3", PersonalRegister.class, args)));
    this.mHashMapTabInfo.put(tabInfo.tag, tabInfo);
    mTabHost.setCurrentTab(0);

    DisplayMetrics dm = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screenWidth = dm.widthPixels;

    TabWidget tabWidget = mTabHost.getTabWidget();
    int count = tabWidget.getChildCount();
    if (count > 1) {
      for (int i = 0; i < count; i++) {
        tabWidget.getChildTabViewAt(i).setMinimumWidth((screenWidth) / 1);
      }
    }

    mTabHost.setOnTabChangedListener(this);
  }
예제 #5
0
파일: Main.java 프로젝트: catch/Gardening
  private void customTabs() {
    /* 对Tab标签的定制 */
    mTabWidget = mTabHost.getTabWidget();
    for (int i = 0; i < mTabWidget.getChildCount(); i++) {
      /* 得到每个标签的视图 */
      View view = mTabWidget.getChildAt(i);
      TextView title = (TextView) view.findViewById(R.id.main_activity_tab_text);

      /* 设置每个标签的背景 */
      if (mTabHost.getCurrentTab() == i) {
        view.setBackgroundResource(R.drawable.number_bg_pressed);
        title.setTextColor(Color.rgb(255, 255, 255));
      } else {
        view.setBackgroundResource(R.drawable.number_bg);
        title.setTextColor(Color.rgb(0, 0, 0));
      }
    }
  }
  @SuppressLint("NewApi")
  public void testTabsAreSelectable() throws Throwable {
    String[] colorChooserTags = {
      mSolo.getString(R.string.color_pre), mSolo.getString(R.string.color_rgb)
    };

    assertTrue("Waiting for DrawingSurface", mSolo.waitForView(DrawingSurface.class, 1, TIMEOUT));
    mSolo.clickOnView(mButtonTopColor);
    mSolo.sleep(COLOR_PICKER_DIALOGUE_APPERANCE_DELAY);

    TabHost tabHost = (TabHost) mSolo.getView(R.id.colorview_tabColors);
    TabWidget colorTabWidget = tabHost.getTabWidget();

    assertEquals("Wrong tab count ", colorTabWidget.getTabCount(), colorChooserTags.length);
    for (int tabChildIndex = 0; tabChildIndex < colorTabWidget.getChildCount(); tabChildIndex++) {
      mSolo.clickOnView(colorTabWidget.getChildAt(tabChildIndex), true);
      mSolo.sleep(500);
      if (colorChooserTags[tabChildIndex].equalsIgnoreCase(mSolo.getString(R.string.color_pre)))
        assertFalse(
            "In preselection tab and rgb (red) string found",
            mSolo.searchText(mSolo.getString(R.string.color_red)));
      else if (colorChooserTags[tabChildIndex].equalsIgnoreCase(
          mSolo.getString(R.string.color_rgb))) {
        assertTrue(
            "In rgb tab and red string not found",
            mSolo.searchText(mSolo.getString(R.string.color_red)));
        assertTrue(
            "In rgb tab and green string not found",
            mSolo.searchText(mSolo.getString(R.string.color_green)));
        assertTrue(
            "In rgb tab and blue string not found",
            mSolo.searchText(mSolo.getString(R.string.color_blue)));
      }
    }
    mSolo.goBack();
  }
예제 #7
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
    mEmptyText = (TextView) findViewById(android.R.id.empty); // 针对SIM卡联系人部分提示
    personList = (ListView) findViewById(R.id.listview); // SIM卡联系人
    phoneList = (ListView) findViewById(R.id.listview1); // 电话联系人
    mEditText = (TextView) findViewById(android.R.id.edit); // 针对手机联系人部分提示
    inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    layout = inflater.inflate(R.layout.add, null);

    // 对话框添加
    addDlg =
        new AlertDialog.Builder(GreenActivity.this)
            .setTitle("添加")
            .setView(layout)
            .setPositiveButton(
                "确定",
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {

                    insert();
                  }
                })
            .setNegativeButton("取消", null)
            .create();

    // 删除确认对话框
    removeDlg =
        new AlertDialog.Builder(this)
            .setTitle("删除")
            .setMessage("确定删除选中的内容吗?")
            .setPositiveButton(
                "确定",
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    // delete();

                    deletesim del = new deletesim();
                    del.execute();
                  }
                })
            .setNegativeButton("取消", null)
            .create();
    // COPY拷贝对话框
    CopyDlg =
        new AlertDialog.Builder(this)
            .setTitle("拷贝到SIM卡")
            .setMessage("确定拷贝选中内容么?")
            .setPositiveButton(
                "确定",
                new DialogInterface.OnClickListener() {

                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    copytosim cp = new copytosim();
                    cp.execute();
                  }
                })
            .setNegativeButton("取消", null)
            .create();

    // TabHost的相关设置
    int width = 55;
    int height = 60;
    final TabHost tabhost = getTabHost();
    tabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));
    // frank
    Drawable localDrawable1 = getResources().getDrawable(R.drawable.sim_icon);
    Drawable localDrawable2 = getResources().getDrawable(R.drawable.phone_icon);
    tabhost.addTab(
        tabhost.newTabSpec("sim").setIndicator("SIM卡联系人", localDrawable1).setContent(R.id.cb));
    tabhost.addTab(
        tabhost.newTabSpec("phone").setIndicator("手机联系人", localDrawable2).setContent(R.id.list));

    final TabWidget tabwidget = tabhost.getTabWidget();

    for (int i = 0; i < tabwidget.getChildCount(); i++) {
      // 设置页签高度和页签内字体属性
      TextView tv = (TextView) tabwidget.getChildAt(i).findViewById(android.R.id.title);
      tabwidget.getChildAt(i).getLayoutParams().height = height;
      tabwidget.getChildAt(i).getLayoutParams().width = width;
      // tabwidget.setBackgroundResource(R.drawable.toolbar_menu_bg);
      tv.setTextSize(15);
      tv.setTextColor(Color.BLACK);
      tv.setGravity(Gravity.CENTER_HORIZONTAL);
    }
    // 监听
    tabhost.setOnTabChangedListener(this);

    /** ************ 默认SIM卡联系人****************** */
    asyncQuery = new MyAsyncQueryHandler(getContentResolver());
    // 异步读取联系人的信息
    asyncQueryContact();
    /** ********************************************* */
  }