如何获得ActionBar的TextView?

时间:2013-06-03 22:49:28

标签: android

我可以使用getCustomView获得ActionBarview。有没有办法从中获取TextView

2 个答案:

答案 0 :(得分:2)

在操作系统版本和设备之间没有任何可靠性。

如果您尝试设置操作栏的标题,请使用setTitle()上的ActionBar。如果你想尝试标题的样式,你应该可以通过主题来做到这一点。

或者,隐藏标题并通过setCustomView()呈现自己的标题。

答案 1 :(得分:0)

递归尝试? (可能不是一个好的解决方案!

static List<TextView> textViews = new ArrayList<TextView>();

public static <T> void searchRecursively(View parent, Class<T> clazz)
{
    if(clazz.isInstance(parent)) textViews.add(clazz.cast(parent));
    if(parent instanceof ViewGroup)
    {
        ViewGroup vg = (ViewGroup) parent;
        int count = vg.getChildCount();
        for(int i = 0; i < count; i++)
        {
            View v = vg.getChildAt(i);
            searchRecursively(v);
        }
    }
}

使用它像:

searchRecursively(theView, TextView.class);
相关问题