Questions about Android Custom TitleBar

Source: Internet
Author: User

First, the default titlebar for Android is this
You can do it by yourself (just change it) titlebar your own layout file how to write it.
My layout file is like this:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "Horizontal" >    <imageview                android:id= "@+id/image_titilebar"        android:layout_width= " Wrap_content "        android:layout_height=" match_parent "        android:background=" @drawable/ic_launcher "        > </ImageView>    <textview         android:text= "Options"        android:layout_width= "Wrap_content"        android:layout_height= "Match_parent"        android:textsize= "20sp"        android:gravity= "center_vertical        " /></linearlayout>

Activity file like this:
Import Android.app.activity;import Android.os.bundle;import Android.view.window;public class MainActivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); This.requestwindowfeature (Window.feature_custom_title); Setcontentview (R.layout.activity_main); GetWindow (). Setfeatureint (Window.feature_custom_title,r.layout.titlebar);}}

But at this time does not run correctly, you need in the Androidmanifest file corresponding activity added Android:theme = "xxxx" OK

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Questions about Android Custom TitleBar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.