【问题标题】:Action Bar's Title Text Size in AndroidAndroid中操作栏的标题文本大小
【发布时间】:2014-07-23 10:07:23
【问题描述】:

你们中有人知道如何获取操作栏标题中的文本大小

我知道我们可以通过使用此代码在 android 中获取 ActionBar

ActionBar ab = getActionBar();

我们可以使用此代码更改该 ActionBar 的标题

ab.setTitle("This is Title");

注意:我不想更改 ActionBar 标题中的 TextSize,因为我可以通过操作 XML 和使用自定义操作栏来做到这一点。我只想知道那个 ActionBar 的 Title 的 TextSize

我假设 ActionBar 在里面使用 TextView 作为标题

我真的很想知道你们中是否有人知道如何从 ActionBar 的 Title 中获取 TextView

或者至少,知道如何从 ActionBar 的 Title 中获取 TextView 的 TextSize

【问题讨论】:

标签: android


【解决方案1】:

非常感谢@shayan pourvatan

这是帮助我的代码

int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
if (actionBarTitleId > 0) {
    TextView title = (TextView) findViewById(actionBarTitleId);
    if (title != null) {
        //pretty much i can do anything after i got this TextView
    }
}

【讨论】:

    【解决方案2】:

    您可以看到appcompat 库的dimens.xml 文件,其中为ActionBar 标题定义了文本大小。

     <!-- Text size for action bar titles -->
        <dimen name="abc_action_bar_title_text_size">18dp</dimen>
    

    【讨论】:

      【解决方案3】:

      据我所知,Action Bar Title id 的 id 是隐藏的,首先你必须得到那个 Acton Bar Title 的 id,例如:-

      int ActionBarTitleID = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
      

      现在在这个 ID 上使用 settext,比如

      TextView yourTextView = (TextView)findViewById(ActionBarTitleID);   
      yourTextView.setTextColor(colorId);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-30
        • 1970-01-01
        • 2012-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多