How to use the default window title style for androids to make my own TextView ?
I thought a lot and made a TextView that has everything that the default title bar has, with the exception of the text shadow (and some padding / fields, etc., I think).
Here, basically, I tried:
MainUI.xml
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); }
title_bar.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myTitle" android:layout_height="fill_parent" android:layout_width="fill_parent" android:textAppearance="@android:style/TextAppearance.WindowTitle" android:background="@android:drawable/title_bar" android:text="This is my new title" />
Edit:
I found some interesting articles in makemachine and anddev .
Although I don't like this, I copied some of the attributes from the style.xml implementation.
Is there a way to avoid copying attributes in this static way?
Below it is shown that almost perfectly, the difference is that the original βcutβ the first 2-3 pixels of the title shadow, but my TextView does not.
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myTitle" android:layout_height="fill_parent" android:layout_width="fill_parent" android:gravity="center_vertical" android:shadowColor="#BB000000" android:shadowRadius="2.75" android:singleLine="true" android:textAppearance="@android:style/TextAppearance.WindowTitle" android:background="@android:drawable/title_bar" android:text="This is my new title" />
It is also important to override the default android: windowTitleBackgroundStyle with a transparent color, since the default includes some add-ons, etc. that you donβt want to wrap your own title bar.
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomTheme" parent="android:Theme"> <item name="android:windowTitleBackgroundStyle">@android:color/transparent</item> </style> </resources>
Remember to include the theme in AndroidManifest.xml