Rajubhai Rathod
Rajubhai Rathod

Reputation: 113

Custom Title Bar in Android Preference Screen

I have Android Preference Screen in which I have tried to add custom Title Bar with extra xml. But I am getting Preference Menu on title bar and unable to set marginBottom. Its looking like below.

enter image description here

My Preference xml is like below

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    

        
        <Preference
            android:defaultValue=""
            android:key="about"
            android:summary="Know About Us From Here"
            android:title="About" />
        
        <CheckBoxPreference
            android:key="background"
            android:summary="Show Image with Status as Background"
            android:title="Background Image" />
        
        <Preference
            android:defaultValue=""
            android:key="more"
            android:summary="Get More Useful Applications By Us"
            android:title="More Application" />
        
        <Preference
            android:defaultValue=""
            android:key="rate"
            android:summary="Give Us Five Star in Play Store and Support Us"
            android:title="Rate Us" />
        <Preference
            android:defaultValue=""
            android:key="shayari"
            android:summary="Download Hindi Shayari Application"
            android:title="Shayari App" />
        
        <Preference
            android:defaultValue=""
            android:key="check"
            android:summary="Download New Quotes Via Click Here"
            android:title="Download New Quotes" />
       
        <CheckBoxPreference
            android:key="checkauto"
            android:summary="Tick to dont download automatically"
            android:title="Dont download Auto" />
        
        <Preference
            android:defaultValue=""
            android:key="share"
            android:summary="You can Share This Application to Your Friends"
            android:title="Share Application" />
        

</PreferenceScreen>

My custom Xml for title is like below

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 xmlns:ads="http://schemas.android.com/apk/res-auto"
                 android:layout_height="fill_parent"
                android:layout_width="fill_parent">
                
    <LinearLayout
        android:id="@+id/titleBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@drawable/title_bar"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="20dp"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/iconImg"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:layout_margin="5dip"
            android:background="@drawable/app_icon" />

        <ImageView
            android:id="@+id/titleImg"
            android:layout_width="160dp"
            android:layout_height="45dp"
            android:layout_gravity="center"
            android:layout_margin="5dip"
            android:background="@drawable/title" />

        <RelativeLayout
            android:id="@+id/pagerBtn"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingRight="2dip" >
        </RelativeLayout>
    </LinearLayout>

    <ListView android:id="@android:id/list" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"/>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        ads:adSize="BANNER"
        android:layout_alignParentBottom="true"
        ads:adUnitId="@string/admob_publisher_id"
         />

</RelativeLayout>

and finally my Preference Java code is like below

public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
        setContentView(R.layout.config);
        mAdView = (AdView) findViewById(R.id.adView);
		mAdView.loadAd(new AdRequest.Builder().build());

		db = new DAO(this);
		db.open();
		
		
		
		pref = getApplicationContext().getSharedPreferences("com.test.app_prefences.xml",0);
		
		tocheck = pref.getInt("highscoresaved",0);

What I am missing or where should I make changes for make header layout complete ? Thanks

Upvotes: 2

Views: 1489

Answers (1)

Amit Vaghela
Amit Vaghela

Reputation: 22955

Add this android:layout_below="@+id/titleBar" to your listview in custom Xml,

try this code to custom Xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:id="@+id/titleBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="20dp"
        android:background="@drawable/cal"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/iconImg"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:layout_margin="5dip"
            android:background="@drawable/approval" />

        <ImageView
            android:id="@+id/titleImg"
            android:layout_width="160dp"
            android:layout_height="45dp"
            android:layout_gravity="center"
            android:layout_margin="5dip"
            android:background="@drawable/back_dark" />

        <RelativeLayout
            android:id="@+id/pagerBtn"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingRight="2dip">

        </RelativeLayout>
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/titleBar" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_gravity="center"
        ads:adSize="BANNER"
        ads:adUnitId="@string/admob_publisher_id" />

</RelativeLayout>

Upvotes: 2

Related Questions