【问题标题】:How to change the indicator color of Sherlock Action Bar Tabs如何更改 Sherlock 操作栏选项卡的指示器颜色
【发布时间】:2014-06-13 04:50:32
【问题描述】:

我正在制作一个需要更改ActionBarTabs 的指示器颜色的android 应用程序。我正在使用 Sherlock 库来实现ActionBarTabs

如何更改 Sherlock ActionBar 中 ActionBarTabs 的默认指示器颜色?

ActionBar actionBar = getSupportActionBar();

// Hide Actionbar Icon
actionBar.setDisplayShowHomeEnabled(false);

// Hide Actionbar Title
actionBar.setDisplayShowTitleEnabled(false);

// Create Actionbar Tabs
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

tariffPlanJSON = getIntent().getExtras().getString("jsondata");

try {
    JSONObject jsonObject = new JSONObject(tariffPlanJSON);
    JSONArray jsonArray = jsonObject.getJSONArray("payload");

    // going through the all tariff plans to see payload has which types of plans.
    for(int index = 0; index < jsonArray.length(); index++) {
        tariffPlan.add(jsonArray.getJSONObject(index).getString("plantype"));
    }

} catch (JSONException e) {
    e.printStackTrace();
}

Iterator<String> tariffPlansIterator = tariffPlan.iterator();
mActionBarTab = new Tab[tariffPlan.size()];

int index = 0;
while(tariffPlansIterator.hasNext()) {
    String planType = tariffPlansIterator.next();
    // creating a new tabs and setting the text to it.
    mActionBarTab[index] = actionBar.newTab().setText(planType);
    mActionBarTab[index].setTabListener(this);
    actionBar.addTab(mActionBarTab[index]);
    ++index;
}

提前致谢。

【问题讨论】:

标签: android android-actionbar actionbarsherlock


【解决方案1】:

使用ActionbarStyleGenerator 设置操作栏的样式。这是迄今为止最简单、最直观的方式。

如何:

使用 UI 为不同的项目选择颜色 完成后点击“下载 .ZIP” ZIP 文件包含您必须复制到项目 res/layout 和 res/drawableXXXX 文件夹中的资源文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多