스마트폰앱

오늘:
2,086
어제:
2,822
전체:
2,720,175

고객센타 : 070-7752-2000
팩스 : 070-7752-2001
휴대폰 : 010-9513-0019
email : voipkorea@yahoo.co.kr

국민은행
(주)제이에스솔루션
047101-04-155519

Flag Counter
■ 무료 : 유선 집전화 휴대폰 ( 한국 미국 중국 카나다) ↔ (국내 해외 여행자 상사 주재원 유학생) / 가입무 무제한무료■

http://www.b2creativedesigns.com/how-to-create-a-custom-title-bar.php


Overview

1. Create a custom title bar

In this tutorial I am going to show you

  • How to create a custom title bar

Create a custom title bar

Create a new project. I call mine Tutorial_CustomTitle. Create a class called MainActivity and an xml layout file called main.xml.

This is how main.xml will look like:

main.xml:

01<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
02    xmlns:tools="http://schemas.android.com/tools"
03    android:layout_width="fill_parent"
04    android:layout_height="fill_parent"
05    android:background="#FFFFFF">
06 
07    <TextView
08        android:layout_width="fill_parent"
09        android:layout_height="wrap_content"
10        android:gravity="center_horizontal"
11        android:textSize="20sp"
12        android:textColor="#000000"
13        android:layout_marginTop="10dp"
14        android:text="Custom title example" />
15 
16</LinearLayout>

Create the layout of the custom title:

custom_title.xml:

01<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
02    xmlns:tools="http://schemas.android.com/tools"
03    android:layout_width="fill_parent"
04    android:layout_height="fill_parent"
05    android:background="#27160e"
06    android:padding="5dp" >
07 
08    <TextView
09        android:id="@+id/tv1"
10        android:layout_width="wrap_content"
11        android:layout_height="wrap_content"
12        android:textSize="16sp"
13        android:textColor="#fbd16d"
14        android:textStyle="bold"
15        android:text="DFDFDFFD"
16        android:layout_alignParentLeft="true"/>
17 
18    <TextView
19        android:id="@+id/tv2"
20        android:layout_width="wrap_content"
21        android:layout_height="wrap_content"
22        android:textSize="14sp"
23        android:textColor="#FFFFFF"
24        android:text="DFDFDFFD"
25        android:layout_alignParentRight="true"/>
26         
27</RelativeLayout>

MainActivity.java:

01public class MainActivity extends Activity {
02 
03    private TextView title1, title2;
04       
05       
06    @Override
07    public void onCreate(Bundle savedInstanceState) {
08        super.onCreate(savedInstanceState);
09        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
10        setContentView(R.layout.main);
11        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
12 
13        title1 = (TextView)findViewById(R.id.tv1);
14        title2 = (TextView)findViewById(R.id.tv2);
15         
16        title1.setText("Chocolate order");
17        title2.setText("Processing...");
18         
19    }
20 
21}

Now if you run the app you'll see that the bottom of the text is cut off, since the title bar has a default height, and there is also an unnecessary padding to the title:

Android custom title

So we need to overwrite the default height of the titlebar. Create a new xml file in the values folder and call it themes.xml:

themes.xml:

1<?xml version="1.0" encoding="utf-8"?>
2<resources>
3    <style name="MyTheme" parent="android:Theme">
4        <item name="android:windowTitleSize">34dp</item>
5        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
6    </style>
7</resources>

Create a new style in styles.xml:

styles.xml:

1<resources>
2    <style name="AppTheme" parent="android:Theme.Light" />
3 
4    <style name="WindowTitleBackground">
5        <item name="android:background">@android:color/transparent</item>
6        <item name="android:padding">0px</item>
7    </style>
8</resources>

Finally, change the application or activity theme in the Manifest to our new theme:

1android:theme="@style/MyTheme"


Android custom title

If you don't set a background color to the custom title and you remove the padding as well, you get the default custom title background:

Android custom title

And that's all! I hope it was clear and not so terrifying as it looks! Feel free to leave any comments.
Thank you for reading it!

Download

packageProject - Tutorial_CustomTitle.zip

조회 수 :
9550
등록일 :
2013.07.15
00:14:24 (*.160.41.148)
엮인글 :
http://webs.co.kr/index.php?document_srl=21579&act=trackback&key=251
게시글 주소 :
http://webs.co.kr/index.php?document_srl=21579
List of Articles
번호 제목 글쓴이 날짜 조회 수
64 Sqlite detail easy tutorial. admin 2017-09-09 190
63 Change package name Linphone Android admin 2017-08-25 301
62 Liblinphone - import Linphone library in Android Studio 2017 admin 2017-08-25 304
61 I am able to build the limphone on mac by follow the steps describe here admin 2017-08-25 297
60 To build liblinphone for Android, you must COMPILATION INSTRUCTIONS admin 2017-08-25 287
59 sipdroid source code admin 2017-08-08 363
58 안드로이드 주소록 전체가져오기 이름만가져오기 사진가져오기 코드 admin 2015-04-13 5649
57 the sipdroid Research Miscellaneous admin 2015-03-26 2763
56 HSS070 English Korean 무료 국제전화 미국 중국 카나다 무료 통화 제공 admin 2014-12-28 4030
55 Softphones admin 2014-09-20 4467
54 /xxxxx/gen already exists but is not a source folder. Convert to a source folder or rename it. admin 2014-09-03 4879
53 CSIPSimple building Rebuilding Detail on Eclips Good All is heare perfect admin 2014-08-15 4828
52 Improving QoE of SIP-based Automated Voice Interaction in Mobile Networks file admin 2014-03-20 5637
51 speex support in android admin 2014-03-19 5864
50 voxmobile Source and how to build admin 2014-02-18 6236
49 PJSIP hung the phone constantly corrected the problem admin 2014-02-09 6672
48 Csipsimple code rebuilding source sip 통신 Call Mechanism admin 2014-02-09 18380
47 Csipsimple code rebuilding source sip 통신 technical interviewer admin 2014-02-09 6629
46 Csipsimple code rebuilding source 주요인터페이스분석 admin 2014-02-09 32732
45 Csipsimple code rebuilding source 다운로드 구성 csipsimple 소스 프로젝트 admin 2014-02-09 7696
44 Android DialogFragment Tutorial admin 2014-02-09 6923
43 Creating a fullscreen DialogFragment with a custom background admin 2014-02-09 9366
42 [Android API] 네트워크 상태 체크하기 admin 2013-12-19 8284
41 [안드로이드] 네트워크 연결 상태 체크 함수. admin 2013-12-19 7613
40 안드로이드 인터넷연결체크 ( 3g/lte/wifi ) 메서드 admin 2013-12-19 13965
39 Android Get Phone Contacts details with Contact Image admin 2013-12-15 6944
38 안드로이드 커스텀 타이틀바 How to add custom title bar to android application admin 2013-10-02 9306
» How to create a custom title bar admin 2013-07-15 9550
36 Rotary Dialer clip art admin 2013-04-20 17195
35 Java 프로그램 실행화일 만들기 : Launch4j admin 2013-02-21 10205
34 java network programming source code, learning socket programming admin 2012-12-04 10331
33 2X Client Configuration | Android Remote Desktop 안드로이드 PC 리모트 데스크탑 admin 2012-12-02 12105
32 WIFI 3G 인터넷 연결 실시간 체크 소스코드 Broadcast Receiver 사용 (Adnroid) admin 2012-10-31 16432
31 통신사별 와이파이 비밀번호 admin 2012-10-31 14407
30 팁, wifi 패스워드 모음집 password admin 2012-10-21 10688
29 Android User Session Management using Shared Preferences admin 2012-10-16 32031
28 Unicode Tables v4 admin 2012-10-16 22976
27 HTML Codes admin 2012-10-16 9649
26 IBM Scan Codes EBCDIC Codes admin 2012-10-16 11823
25 ASCII Table and Description admin 2012-10-16 11131
24 How to Show Alert Dialog in Android (간단하고 쉬운설명) admin 2012-10-15 22131
23 How to read contacts on Android 2.0 admin 2012-10-14 13171
22 WIFI 3G 인터넷 연결 체크 소스코드 직접 사용한 코드 android admin 2012-10-14 15089
21 Android Detect Internet Connection Status admin 2012-10-12 20645
20 JAVA + SSL (server and client examples) admin 2012-10-07 22184
19 Querying The Android Contact Database admin 2012-09-30 10537
18 Manage Contacts android admin 2012-09-30 12497
17 Android Contacts API 2 example admin 2012-09-30 13596
16 Android 2.0 주소록 동기화 기능 admin 2012-09-30 38736
15 안드로이드용 앱 개발 마켓등록 까지 해본거 샘플 무료국제전화 앱 FreeDialer admin 2012-09-27 14574
14 아이폰 IPhone 앱 개발 기본 admin 2012-09-27 11228
13 [안드로이드/개발] Intent admin 2012-09-23 17572
12 안드로이드 타이머 절적한 설명과 간단한소스코드 등 안드로이드 프로그램 설명 깔끔 admin 2012-09-23 28220
11 google voice source code admin 2012-09-22 10525
10 [안드로이드] 서버/클라이언트 소켓(Socket) 통신하기 admin 2012-09-20 20390
9 FreeDial 무료국제전화는 프리미엄 국제전화 다이렉트 회선사용 admin 2012-09-20 11611
8 Android SQlite 사용 admin 2012-09-04 11138
7 안드로이드마켓에 앱 등록하는 순서 admin 2012-08-19 41835
6 전화관련 안드로이드함수 admin 2012-08-18 15147
5 자바 ,이클립스,Android SDK, ADT 설치하여 무료국제전화 다이얼러를 만들어봅시다. admin 2012-08-06 15698
4 아이폰용 무료국제전화용 무료 다이얼러 Speedydialer 설치및 사용방법 file admin 2012-07-14 11055
3 접속번호 + 상대방번호 # 를 주소록에 전화번호로 저장하여 사용하면 편리하다 admin 2012-06-17 13016
2 App Store - ILD Dialer admin 2012-06-17 9599
1 한국휴대폰에서 미국 중국 카나다 무료 국제전화 서비스 admin 2012-04-27 9955