Hi i have set up a custom title bar but the app crashes and i don’t get any error log in LogCat, i’m going crazy. Here’s is some code, can you experts see what’s wrong?
boolean isCustomTitleSupported;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isCustomTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.about);
customizeTitleBar("My Title");
public void customizeTitleBar(String title){
if(isCustomTitleSupported){
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitlebar);
TextView customTitleText = (TextView)findViewById(R.id.customtitle);
customTitleText.setText(title);
customTitleText.setTextColor(Color.WHITE);
}
}
customtitlebar.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/customtitle"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textStyle="bold"
android:padding="3px"
/>
</LinearLayout>
some help will be appreciated
Thanks!!
EDIT: i noticed that i wasn’t extending Activity but BaseActivity a superclass i created to have the menu available in all of my activities. So i changed back to extend Activity and it’s working but this is a problem because i need menus too. Is there any tricks so i could keep extending BaseActivity and even get the title bar to work?
You are trying to extract the
customtitleTextView from the wrong layout. When you usefindViewByIdit defaults to your current activity’s layout, which you set toR.layout.about. You need to use a layout inflater to inflateR.layout.customtitlebarand then callfindViewByIdfrom that (since thecustomtitleview is in thecustomtitlebarlayout).Something like this: