本文实例讲述了AndroID编程自定义Title bar(标题栏)的方法。分享给大家供大家参考,具体如下:
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" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerVertical="true" androID:layout_toRightOf="@+ID/TitleTvleft" androID:paddingleft="3dip"></Progressbar></relativeLayout>
更多关于AndroID相关内容感兴趣的读者可查看本站专题:《Android视图View技巧总结》、《Android布局layout技巧总结》、《@L_403_2@》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体 *** 作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》及《Android控件用法总结》
希望本文所述对大家AndroID程序设计有所帮助。
总结以上是内存溢出为你收集整理的Android编程自定义title bar(标题栏)示例全部内容,希望文章能够帮你解决Android编程自定义title bar(标题栏)示例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)