安卓Api Demo学习 App/Activity/Custom Title

来源:互联网 发布:java 策略算法 编辑:程序博客网 时间:2024/05/16 19:38

首先要告诉系统自定义的类型

核心函数requestWindowFeature。一般用来自定义标题,以及标题栏进度图形,或者让程序没有title

 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
 setContentView(R.layout.custom_title);
 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);  <--这里设置Title的布局


Title的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView android:id="@+id/left_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="@string/custom_title_left" />
    <TextView android:id="@+id/right_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="@string/custom_title_right" />
</RelativeLayout>


final TextView leftText = (TextView) findViewById(R.id.left_text);  取得标题中的Textview组件

leftText.setText(leftTextEdit.getText()); 设置文字


效果如下