zoukankan      html  css  js  c++  java
  • 如何定制Activity的标题栏

     requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

            setContentView(R.layout.main);

            //自定义标题栏
            mWindow = getWindow();
            mWindow.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);

    titlebar.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
    >
            <TextView
                    android:text="@string/app_name"
                    android:textColor="#000"
                    android:paddingRight="3.0dip"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            <TextView
                    android:text="@string/battery_text"
                    android:textColor="#000"
                    android:paddingRight="3.0dip"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            <TextView
                    android:id="@+id/battery_text"
                    android:textColor="#00f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
    </LinearLayout>

     上述的话只是适合android4.0一下的版本,如果需要针对android4.0以上的版本的话需要我们使用自己的样式

      <style name="TitleBackgroundColor">
             <item name="android:background">@color/background_color</item>
         </style>
         
         <style name="titlestyle" parent="android:Theme" >
             <item name="android:windowTitleSize">40dip</item>  
             <item name="android:windowTitleBackgroundStyle">@style/TitleBackgroundColor</item>
         </style> 
    然后在配置文件中加上,OK
    <activity android:name="com.ygl.ui.LoginActivity" android:theme="@style/titlestyle" ></activity>
  • 相关阅读:
    Jmeter 添加信息头
    Jmeter 添加 计数器
    Jmeter 用户定义的变量的使用
    Jmeter 获取系统时间
    Fiddler抓包工具使用技巧
    使用adb安装apk包到手机上的安装步骤:
    如何验证所使用的电脑Windows系统是正版还是盗版的方法
    VMware 15 虚拟机安装 win 7 操作系统步骤
    MySQL在windows上安装过程
    SecureCRT的下载、安装过程
  • 原文地址:https://www.cnblogs.com/DASOU/p/4261038.html
Copyright © 2011-2022 走看看