自定义标题栏一共有四步,下面逐步介绍: 一:在strings.xml文件中配置标题栏的背景和大小 [html] view plain copy
  1. <stylename="CustomWindowTitleBackground">
  2. <!--背景图片-->
  3. <itemname="android:background">@drawable/home_top</item>
  4. </style>
  5. <stylename="title_bar"parent="android:Theme">
  6. <itemname="android:windowTitleSize">40dp</item>
  7. <itemname="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
  8. </style>

二:配置AndroidMainfest.xml文件中相应的activity: [html] view plain copy
  1. <activityandroid:name=".activity.PlazaActivity">
  2. <spanstyle="white-space:pre"></span><intent-filter>
  3. <actionandroid:name="android.intent.action.MAIN"
  4. android:theme="@style/title_bar"/>
  5. <categoryandroid:name="android.intent.category.LAUNCHER"/>
  6. </intent-filter>
  7. </activity>



三:在layout文件夹中添加自定义标题栏的布局文件:title_bar.xml [html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content">
  5. <TextView
  6. android:id="@+id/tvTitle"
  7. android:layout_width="wrap_content"
  8. android:layout_height="40dp"
  9. android:background="@drawable/home_top"
  10. android:gravity="center"
  11. android:textColor="#ffffff"
  12. android:textSize="30sp">
  13. </TextView>
  14. <!--圆形进度条-->
  15. <ProgressBar
  16. android:id="@+id/progressBar"
  17. android:layout_width="30dp"
  18. android:layout_height="30dp"
  19. android:layout_alignParentRight="true"
  20. android:layout_marginTop="5dp">
  21. </ProgressBar>
  22. </RelativeLayout>

四:准备就绪,最后在相应的activity中声明使用自定义标题栏,例如MainActivity.java: [java] view plain copy
  1. publicvoidonCreate(BundlesavedInstanceState){
  2. super.onCreate(savedInstanceState);
  3. //声明使用自定义标题栏,注意代码的顺序
  4. requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
  5. setContentView(R.layout.plaza);
  6. getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
  7. R.layout.title_bar);
  8. }
四步完成自定义标题栏。
因为上述例子我用到了圆形的进度条,就简单介绍下它的使用:
进度条布局文件:progress.xml [html] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content">
  5. <ProgressBarandroid:id="@+id/progress"
  6. android:layout_width="wrap_content"
  7. android:layout_height="wrap_content"
  8. android:layout_gravity="center_vertical"
  9. style="?android:attr/progressBarStyleSmallTitle">
  10. </ProgressBar>
  11. </LinearLayout>



在相应的activity中声明: [java] view plain copy
  1. publicvoidonCreate(BundlesavedInstanceState){
  2. super.onCreate(savedInstanceState);
  3. //声明使用系统默认的圆形进度条。
  4. requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  5. setContentView(R.layout.main);
  6. getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS,R.layout.progress);
  7. setProgressBarIndeterminateVisibility(true);//开始进度条
  8. setProgressBarIndeterminateVisibility(false);//结束进度条
  9. }

更多相关文章

  1. 一款常用的 Squid 日志分析工具
  2. GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
  3. RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
  4. Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
  5. dlopen failed: library "/system/lib/libxxx.so" needed or dlo
  6. Android学习笔记之数据库
  7. Android读写文件!!!!
  8. Android中JNI的调用生成头文件步骤
  9. android下的文件权限

随机推荐

  1. android N 版本问题
  2. android实现开机自动播放音乐实例(Broadca
  3. 赵雅智_Android的getResources()资源引用
  4. Android XML Shape使用入门
  5. Android SDK和ADT介绍
  6. Android 横竖屏切换 activity变化详解
  7. ListView滚动小滑块
  8. Android的ListView中判断其内容已滚动到
  9. 关于android 获得图片的总结
  10. Android Parcelable 源码解析