@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    final boolean customTitle= requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);    setContentView(R.layout.main);    if ( customTitle ) {        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Set your layout for title here and mention your button in this layout);    }    final TextView myTitleText = (TextView) findViewById(R.id.myTitle);    if ( myTitleText != null ) {        myTitleText.setText("NEW TITLE");        myTitleText.setBackgroundColor(Color.BLUE);    }}
上述代码只能自定义标题栏,但不能改变标题栏的大小、自定义标题栏属性如下: 原理是这样的. 直接像上述代码那样添加title仅仅是把一个子界面添加到原有的title上的, 并没有改变原来的属性, 比如 标题栏大小, 标题栏背景. 这些需要在theme 主题里面定义. 因此先定义一个style, 若修改背景请修改android:windowTitleBackgroundStyle 若修改标题栏高度,请修改android:windowTitleSize 例子: <?xmlversion="1.0"encoding="utf-8"?>
<resourcesxmlns:android="http://schemas.android.com/apk/res/android">


<stylename="CustomWindowTitleBackground">
<itemname="android:background">#565656</item>
</style>


<stylename="test"parent="android:Theme">
<itemname="android:windowTitleSize">50dp</item>
<itemname="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
在程序的android manifest.xml中对应activity中添加属性android:theme = "@style/test" 就可以了

更多相关文章

  1. Android Notification 填充 自定义布局
  2. android 自定义组件随着手指自动画圆
  3. 【Android】定义HttpPost连接超时
  4. android 自定义TextView中Html超链接点击事件详解
  5. 自定义主题
  6. Android 自定义shape圆形按钮

随机推荐

  1. Android Activity onPause与onStop
  2. Android获取SIM卡信息--TelephonyManager
  3. rename application package 遇到的excep
  4. android一些网址,其实两个就基本够用了
  5. Android中的软引用、弱引用
  6. Android Bitmap与String的相互转换
  7. Android 界面设计工具 droiddraw
  8. Android 自定义Gif动画
  9. 如何让Android支持GIF图片
  10. Android studio的ndk开发