Android編程自定義title bar(標(biāo)題欄)示例
本文實例講述了Android編程自定義title bar(標(biāo)題欄)的方法。分享給大家供大家參考,具體如下:
package com.test;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ProgressBar;
import android.widget.TextView;
public class Test extends Activity {
/** Called when the activity is first created. */
boolean customTitleSupported;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//check if custom title is supported BEFORE setting the content view!
customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
//set custom titlebar
customTitleBar(getText(R.string.app_name).toString(), "hello world!!");
}
public void customTitleBar(String left, String right) {
if (right.length() > 20)
right = right.substring(0, 20);
// set up custom title
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.title);
TextView titleTvLeft = (TextView) findViewById(R.id.titleTvLeft);
TextView titleTvRight = (TextView) findViewById(R.id.titleTvRight);
titleTvLeft.setText(left);
titleTvRight.setText(right);
ProgressBar titleProgressBar;
titleProgressBar = (ProgressBar) findViewById(R.id.leadProgressBar);
// hide the progress bar if it is not needed
titleProgressBar.setVisibility(ProgressBar.GONE);
}
}
}
布局文件: title.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/titleTvLeft" android:text="left"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/titleTvRight" android:text="right" android:layout_alignParentRight="true"></TextView> <ProgressBar android:id="@+id/leadProgressBar" style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@+id/titleTvLeft" android:paddingLeft="3dip"></ProgressBar> </RelativeLayout>
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android開發(fā)學(xué)習(xí)路線的七大階段
這篇文章主要介紹了Android開發(fā)學(xué)習(xí)路線的七大階段,本文講解了Java面向?qū)ο缶幊?、Java Web開發(fā)、android UI編程、android網(wǎng)絡(luò)編程與數(shù)據(jù)存儲、android手機(jī)硬件管理等七大階段,需要的朋友可以參考下2015-04-04
Android?RxJava與Retrofit結(jié)合使用詳解
RxJava和Retrofit的結(jié)合使用估計已經(jīng)相當(dāng)普遍了,自己工作中也是一直都在使用。在使用的過程中我們都會對其進(jìn)行封裝使用,GitHub上也有很多封裝好的項目可以直接拿來使用,其實對于開源框架的二次封裝有時候針對不同的業(yè)務(wù)邏輯封裝的過程中也多多少少有些不同2023-03-03
android事件分發(fā)機(jī)制的實現(xiàn)原理
本篇文章主要介紹了android事件分發(fā)機(jī)制的實現(xiàn)原理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09
Android多功能時鐘開發(fā)案例(基礎(chǔ)篇)
這篇文章主要為大家詳細(xì)介紹了Android多功能時鐘開發(fā)案例的基礎(chǔ)知識,為開發(fā)Android時鐘打下基礎(chǔ),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-05-05
Android實現(xiàn)整理PackageManager獲取所有安裝程序信息
這篇文章主要介紹了Android實現(xiàn)整理PackageManager獲取所有安裝程序信息的方法,實例分析了Android使用PackageManager獲取安裝程序信息的具體步驟與相關(guān)技巧,需要的朋友可以參考下2016-01-01
mui.init()與mui.plusReady()區(qū)別和關(guān)系
給大家分享一下在使用MUI進(jìn)行APP開發(fā)的時候,mui.init()與mui.plusReady()區(qū)別以及使用上不同之處。2017-11-11

