Skip to content Skip to sidebar Skip to footer

Title Bar With Fragment Overlap With List View

I'm beginner in Android. I have a title bar which is separately placed in tool_bar.xml . Now i have two fragments. From one fragment i create a new activity which have to include t

Solution 1:

In your OnCreate() method of your activity, you should be setting the toolbar for the current activity:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category__blogs);
    Toolbartoolbar= (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar)
}

Activity_Category_Blogs layout will contain this:

<android.support.v7.widget.Toolbarandroid:layout_height="wrap_content"android:layout_width="match_parent"android:background="@color/ColorPrimary"android:elevation="2dp"android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"xmlns:android="http://schemas.android.com/apk/res/android"android:layout_alignParentTop="true"/><LinearLayoutandroid:layout_marginTop="?attr/actionBarSize"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_weight="1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textAppearance="?android:attr/textAppearanceMedium"android:minLines="1"android:id="@+id/textViewTitle" /></LinearLayout></android.support.v7.widget.Toolbar>

tool_bar file will have the same toolbar used in your activity without the extra controls:

<android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_alignParentTop="true"/>

In your fragment OnCreate() method you should be able to set the text of textViewTitle:

((TextView)findViewById(R.id.textViewTitle)).setText("XYZ");

Solution 2:

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="fill_parent"android:layout_height="wrap_content"tools:context="com.example.talha.test_fragement.Category_Blogs"xmlns:ads="http://schemas.android.com/apk/res-auto"><includelayout="@layout/tool_bar"android:id="@+id/toolbar" /><RelativeLayoutandroid:layout_width="fill_parent"android:layout_below="@+id/toolbar"android:layout_height="fill_parent"><ListViewandroid:id="@android:id/list"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_above="@+id/adView"android:divider="#b5b5b5"android:dividerHeight="1dp"android:layout_alignParentBottom="false"
        /><TextViewandroid:id="@android:id/empty"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:layout_gravity="right|top" />

</RelativeLayout >

Post a Comment for "Title Bar With Fragment Overlap With List View"