自定义Android(安卓)标题栏TitleBar布局
16lz
2021-12-04
自定义Android 标题栏TitleBar布局
方法一、
在res/value 里建一XML文档,取名为mytitlebar,内容如下:
其中“<item name="android:windowNoTitle">false</item>”一句如果值为true,将没有标题栏,如果要显示标题栏,这句可不写。下一句是标题大小,接下来是背景颜色。
在程序的android manifest.xml中对应activity(即要自定义TitleBar的那个Activity)中添加属性 android:theme = "@style/myTheme" 就可以了
方法二、(带按钮的标题栏)
建一layout 名为mytitlebar.xml内容如下:
就一个简单的 button,可以自己加其它的元素。
然后在java代码的onCreate中加入如下,顺序不能乱
方法一、
在res/value 里建一XML文档,取名为mytitlebar,内容如下:
<?xml version="1.0" encoding="utf-8"?><resources xmlns:android="http://schemas.android.com/apk/res/android"><style name="myTitleBg"> <item name="android:background">#556B2F</item></style><style name="myTheme" parent="android:Theme"> <item name="android:windowNoTitle">false</item> <item name="android:windowTitleSize">50dp</item> <item name="android:windowTitleBackgroundStyle">@style/myTitleBg</item></style></resources>
其中“<item name="android:windowNoTitle">false</item>”一句如果值为true,将没有标题栏,如果要显示标题栏,这句可不写。下一句是标题大小,接下来是背景颜色。
在程序的android manifest.xml中对应activity(即要自定义TitleBar的那个Activity)中添加属性 android:theme = "@style/myTheme" 就可以了
方法二、(带按钮的标题栏)
建一layout 名为mytitlebar.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"> <Button android:id="@+id/pause" android:layout_width="wrap_content" android:layout_height="30px" /> </LinearLayout>
就一个简单的 button,可以自己加其它的元素。
然后在java代码的onCreate中加入如下,顺序不能乱
super.onCreate(savedInstanceState); // 注意顺序 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // 注意顺序 setContentView(R.layout.main); // 注意顺序 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.mytitlebar); // 注意顺序
更多相关文章
- android Intent API8
- 介绍一下android的各种权限。 代码如下: Html代码 <manifestxmlns
- Android(安卓)自定义渐变背景
- android wifi状态机原理
- android webView与js交互
- Android内嵌H5(2)
- Android开发由eclipse转Android(安卓)Studio中一些常见出错问题
- android摄像头采集和预览-第二种方法
- Android(安卓)Studio 错误 Duplicate files copied in APK META-