iGio90 iGio90 - 1 year ago 55
Android Question

Get ActionBar TextView (title) in android

as per title i need to retrieve the textview that rapresent the activity title located in the ActionBar. I'm able to get the ActionBar view with the following method:

private View getActionBarView() {
View v = mWindow.getDecorView();
int resId = getResources().getIdentifier("action_bar_container", "id", "android");
return v.findViewById(resId);

Does anyone know the id of the TextView so i can findViewById inside the actionbar view?

well, i solved with the same method but by changing the id:

private TextView getActionBarTitle() {
View v = mWindow.getDecorView();
int resId = getResources().getIdentifier("action_bar_title", "id", "android");
return v.findViewById(resId);

Answer Source

All of the built-in Android layouts can be found in the SDK under:


I think the one you are looking for in this case is action_bar_title_item.xml.
This is v19's:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at


     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    <TextView android:id="@+id/action_bar_title"
              android:ellipsize="end" />
    <TextView android:id="@+id/action_bar_subtitle"
              android:visibility="gone" />

Layouts can and do differ between API versions. In general the IDs will match but I can't say this would be true for every single layout and will always be so it's best to quickly look at each for differences if you are planning to use specific built in resources like this in case.

To do that, you will have to grab individual copies of the source code to look at each API version.
This can either be done though:

  • Your IDE: use Android's ADT plugin for your IDE of choice (Eclipse or AndroidStudio)
  • Manual method: calling the SDK's version yourself which is located within the SDK at:


You obviously need only grab the versions you are supporting and as I mentioned above each will have its own folder named after its single int version number. Eg:


Uh-oh! No layout for API-10. If you want to use the action_bar_title_item.xml layout in that version of the API you can include and use Sherlock ActionBar or perhaps copy or modify the v11 layout to:

.../YourApp/res/layout-v10/action_bar_title_item.xml               (Eclipse)
.../YourApp/app/src/main/res/layout-v10/action_bar_title_item.xml  (Android Studio)

Your call. The same can be done it you just want to customise the layout. Copy the android built in version to your own layout folders and tweak to your heart's content. Just be mindful of what folders you place the files in so that they are overriding the desired, correct versions.