Please, let me know, how to add buttons to the title bar.
- Remove the title completely and create a custom title with an ImageView for example.
or
- Use another approach
My Goal is something similar to the Facebook app
UPDATE: API Level >= 10
Please, let me know, how to add buttons to the title bar.
or
My Goal is something similar to the Facebook app
UPDATE: API Level >= 10
My solution using custom ViewGroup (from RelativeLayout) so I can use it in different activities without copy paste xml. This is a simple example that update a text view with the title. You can add buttons to relative layout ang get them work in the way you need.
But if you've only an Activity it's better if you include it as a sub layout of the main layout of your activity
public class StatusBar extends RelativeLayout {
private TextView textViewTitle;
public StatusBar(Context context, AttributeSet attrs) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.ui_status_bar, this, true);
super(context, attrs);
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
textViewTitle = (TextView) findViewById(R.id.textViewTitle);
}
private void updateStatusBar(String title) {
this.textViewTitle.setText(title)
}
}
And the ui_status_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/theme_color_darker"
android:gravity="center_vertical" >
<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</RelativeLayout>
in your activity you can use it like this:
<com.uicomponents.statusbar.StatusBar
android:id="@+id/statusBar"
style="@style/status_bar" />
I think, it's best practice to use Android's Actionbar. Prefer action menu instead of buttons in custom title bar.
Please see :
And for the further implementation of actionbar please refer :