Android首选项屏幕中的自定义标题栏

时间:2016-02-06 04:53:49

标签: java android xml android-layout android-studio

我有Android weatherText,其中我尝试使用额外的xml添加自定义Preference Screen。但我在标题栏上收到Title Bar,无法设置Preference Menu。它看起来像下面。

enter image description here

我的偏好xml 如下所示



marginBottom




标题的自定义Xml 如下所示



<?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>
&#13;
&#13;
&#13;

最后我的Preference Java代码如下所示

&#13;
&#13;
<?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>
&#13;
&#13;
&#13;

我缺少什么或者我应该在哪里更改make header layout? 感谢

1 个答案:

答案 0 :(得分:2)

将此android:layout_below="@+id/titleBar"添加到自定义Xml 中的列表视图中,

尝试使用此代码自定义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>