<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="44dp" android:orientation="horizontal" android:gravity="center_vertical" android:background="#FFFFFF" > <ImageView android:id="@+id/dxLogo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:src="@drawable/dx_icon" android:layout_marginRight="10dip" /> <TextView android:id="@+id/titleHeading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" style="@style/titleBarHeading" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="appTheme" parent="@android:style/Theme.Black"> <item name="android:textColor">#444444</item> <item name="android:windowTitleBackgroundStyle">@style/titleBarBackground</item> <item name="android:windowTitleSize">44dip</item> </style> <style name="titleBarHeading" parent="@android:style/TextAppearance"> <item name="android:textSize">17sp</item> <item name="android:textStyle">bold</item> <item name="android:textColor">#444444</item> </style> <style name="titleBarBackground"> <item name="android:background">@android:color/transparent</item> <item name="android:padding">0px</item> </style> </resources>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/appTheme" >
public class CashBookActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title); } }
public class FormActivity extends CashBookActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.form); TextView tvHeading = (TextView) findViewById(R.id.titleHeading); tvHeading.setText("Add New Transaction"); } }
5 Comments
This is a very good tutorial.please help me.What are the contents of window_title.xml and form.xml
Rohit,
The first piece of code is saved as window_title.xml. form.xml can contain any thing, it does not concern the functionality. This is you activity layout.
Hope this helps,
Hi I have used this technique. But before running the App I am unable to remove some errors. I have created the style folder in res directory. In which I have created the style file (appTheme). But I am seeing the error on style folder. I have tried clean build that didn’t work.
Here is the screenshot
https://www.dropbox.com/s/8kc91ht2i9dgol5/shot.png
I tried this, but now when I extend my main activity to the CashBookActivity, I get an error message in the main activity’s layout file:
Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style ‘textViewStyle’ in current theme
Any idea why…? Otherwise … thanks for the great tutorial! 🙂
You are referencing a style that doesn’t exist:
style
=
"@style/titleBarHeading" ?