Reputation: 63546
I can get an ActionBar
's view
using getCustomView. Is there a way to get its TextView
from that?
Upvotes: 0
Views: 148
Reputation: 117587
Try recursively? (might not be a good solution though!)
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);
}
}
}
Use it like:
searchRecursively(theView, TextView.class);
Upvotes: 0
Reputation: 1006674
Not in any way that is going to be reliable across OS versions and devices.
If you are attempting to set the title of the action bar, please use setTitle()
on ActionBar
. If you are trying to style the title, you should be able to do that via a theme.
Or, hide the title and render your own via setCustomView()
.
Upvotes: 2