【问题标题】:Custom Title Bar in Android Preference ScreenAndroid首选项屏幕中的自定义标题栏
【发布时间】:2016-05-16 05:11:50
【问题描述】:

我有 Android Preference Screen,我尝试在其中添加带有额外 xml 的自定义 Title Bar。但我在标题栏上收到Preference Menu,无法设置marginBottom。如下所示。

我的 Preference 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>

我的 自定义 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_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>

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

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);

我缺少什么或者我应该在哪里进行更改以使标题布局完整? 谢谢

【问题讨论】:

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


    【解决方案1】:

    将此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>
    

    【讨论】:

    • 谢谢!它拯救了我的一天:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 2022-11-12
    • 2011-09-11
    • 1970-01-01
    • 2011-07-31
    相关资源
    最近更新 更多