iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android编程自定义title bar(标题栏)示例
  • 867
分享到

Android编程自定义title bar(标题栏)示例

示例title标题栏barAndroid 2022-06-06 07:06:56 867人浏览 八月长安
摘要

本文实例讲述了Android编程自定义title bar(标题栏)的方法。分享给大家供大家参考,具体如下: package com.test; import android.

本文实例讲述了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 {
  
 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>

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android视图View技巧总结》、《Android布局layout技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体操作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。

您可能感兴趣的文章:Android中BaseActivity自定义标题栏Android自定义状态栏颜色与应用标题栏颜色一致Android 自定义标题栏背景Android实现自定义标题栏的方法Android中自定义标题栏样式的两种方法Android 自定义标题栏 显示网页加载进度的方法实例Android 自定义标题栏的实例详解


--结束END--

本文标题: Android编程自定义title bar(标题栏)示例

本文链接: https://www.lsjlt.com/news/23554.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作