zoukankan      html  css  js  c++  java
  • android自定义title

    1. 自定义一个title.xml布局

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" 
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/windowTitleSize"  
        style="?android:attr/windowTitleBackgroundStyle">
    
        <TextView
            android:id="@+id/tbartxt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:textSize="15dp"
            android:textColor="#ffffff"
            android:paddingTop="3.0dip" 
            android:paddingBottom="3.0dip" 
            android:gravity="center">
            
        </TextView>
    
    </LinearLayout>

    2. 

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.main);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);

    需要注意的是这三句话的顺序不能变。到这里只是改变了title的布局,下面改变背景和高度,这就需要改变Activity的theme。

    在values文件夹下新建文件style.xml:

    <?xml version=”1.0″ encoding=”utf-8″?>
    <resources>
    <style name=”CustomWindowTitleBackground”>
    <item name=”android:background”>@drawable/bg_title</item>
    </style>
    <style name=”title_style” parent=”android:Theme”>
    <item name=”android:windowTitleSize”>44dip</item>
    <item name=”android:windowTitleBackgroundStyle”>@style/CustomWindowTitleBackground</item>
    </style>
    </resources>

    最后在AndroidManifest.xml里面加上:

    <activity android:name=”.sysinfo”
    android:label=”@string/app_name”
    android:screenOrientation=”portrait”
    android:theme=”@style/title_style”
    >

  • 相关阅读:
    30款超酷的HTTP 404页面未找到错误设计
    java与java学习路线
    程序员最核心的竞争力
    群智能优化算法-测试函数matlab源码
    如何用Latex合并多个pdf文件?
    Latex--TikZ和PGF--高级文本绘图,思维绘图,想到--得到!
    学无止境 气有浩然
    Latex中定义、定理、引理、证明 设置方法总结
    WeUI
    微信JS SDK Demo 官方案例
  • 原文地址:https://www.cnblogs.com/shenbin/p/2681694.html
Copyright © 2011-2022 走看看