Android custom title

Source: Internet
Author: User

There are two methods:

1. Hide the title of the system and make a title-like effect on the layout.
2. Request the system service to make the system title use our defined style.

Now let's talk about the second type. The Code is as follows:

1. Create a title. xml file in the layout file.

<?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="wrap_content"    android:orientation="horizontal" ><TextView     android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="custom title"    android:id="@+id/tv"    />    <ImageView     android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:src="@drawable/ic_launcher"    /></LinearLayout>
2. Code in the activity:

Public class CustomtitleActivity extends Activity {@ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // request the system to use a custom title. The code must be written to boolean flag = requestWindowFeature (Window. FEATURE_CUSTOM_TITLE); setContentView (R. layout. main); if (flag) {getWindow (). setFeatureInt (Window. FEATURE_CUSTOM_TITLE, R. layout. title );}}}





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.