Its quite small article about reading custom attributes from theme in Activity code.

First we need to define our custom attribute.

<attr name="TitleText" format="reference|string"/>

Apply this attribute to Activity’s theme

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">        
	<item name="TitleText">@string/app_name</item>

Read this attribute in activity and set TextView text.

TextView text = (TextView) findViewById(;
TypedValue lTypedText = new TypedValue();

getTheme().resolveAttribute(R.attr.TitleText, lTypedText, true);
//check if we have value set
if (lTypedText.resourceId != 0) {
    String title = getResources().getString(lTypedText.resourceId);

Full source code for this article is available on GitHub