首页 > 移动平台 > 详细

Android UI:Layout 自定义标题栏

时间:2015-05-14 16:19:35      阅读:265      评论:0      收藏:0      [点我收藏+]

1.新建一个layout文件,如mycustomtitle.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="45dp"
    android:background="@color/blue" >

    <ImageButton
        android:id="@+id/share"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"        
        android:layout_alignParentRight="true"
        android:src="@drawable/share"
        android:background="@color/blue"
        android:contentDescription="@string/share" 
        android:paddingRight="5dp"/>
    

    <ImageButton
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/back"
        android:src="@drawable/back"
        android:background="@color/blue"
        android:padding="5dp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="@string/title"
        android:textColor="#fff"
        android:textSize="20sp"
        android:textStyle="bold" />

</RelativeLayout>

效果如图所示

 

技术分享

2.在Java中调用该标题的方法,如下:注意代码的顺序,很重要

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity);        
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.mycustomtitle); 

}

 

Android UI:Layout 自定义标题栏

原文:http://www.cnblogs.com/Bubls/p/4503414.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!