한국어

스마트폰앱

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

     페북공유

   ◎위챗 : speedseoul


  
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


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

조회 수 :
15464
등록일 :
2013.07.15
00:14:24 (*.160.41.148)
엮인글 :
http://webs.co.kr/index.php?document_srl=21579&act=trackback&key=b86
게시글 주소 :
http://webs.co.kr/index.php?document_srl=21579
List of Articles
번호 제목 글쓴이 날짜 조회 수
66 mjsip sip sample code program admin 2019-09-07 54
65 Package org.linphone.core Description admin 2017-10-22 4781
64 Sqlite detail easy tutorial. admin 2017-09-09 4945
63 Change package name Linphone Android admin 2017-08-25 5116
62 Liblinphone - import Linphone library in Android Studio 2017 admin 2017-08-25 5465
61 I am able to build the limphone on mac by follow the steps describe here admin 2017-08-25 5020
60 To build liblinphone for Android, you must COMPILATION INSTRUCTIONS admin 2017-08-25 5337
59 sipdroid source code admin 2017-08-08 5120
58 안드로이드 주소록 전체가져오기 이름만가져오기 사진가져오기 코드 admin 2015-04-13 24877
57 the sipdroid Research Miscellaneous admin 2015-03-26 8398
56 HSS070 English Korean 무료 국제전화 미국 중국 카나다 무료 통화 제공 admin 2014-12-28 14463
55 Softphones admin 2014-09-20 10779
54 /xxxxx/gen already exists but is not a source folder. Convert to a source folder or rename it. admin 2014-09-03 13975
53 CSIPSimple building Rebuilding Detail on Eclips Good All is heare perfect admin 2014-08-15 11707
52 Improving QoE of SIP-based Automated Voice Interaction in Mobile Networks file admin 2014-03-20 12530
51 speex support in android admin 2014-03-19 11910
50 voxmobile Source and how to build admin 2014-02-18 13225
49 PJSIP hung the phone constantly corrected the problem admin 2014-02-09 13195
48 Csipsimple code rebuilding source sip 통신 Call Mechanism admin 2014-02-09 73639
47 Csipsimple code rebuilding source sip 통신 technical interviewer admin 2014-02-09 13215
46 Csipsimple code rebuilding source 주요인터페이스분석 admin 2014-02-09 178343
45 Csipsimple code rebuilding source 다운로드 구성 csipsimple 소스 프로젝트 admin 2014-02-09 15055
44 Android DialogFragment Tutorial admin 2014-02-09 12953
43 Creating a fullscreen DialogFragment with a custom background admin 2014-02-09 16109
42 [Android API] 네트워크 상태 체크하기 admin 2013-12-19 18219
41 [안드로이드] 네트워크 연결 상태 체크 함수. admin 2013-12-19 14787
40 안드로이드 인터넷연결체크 ( 3g/lte/wifi ) 메서드 admin 2013-12-19 20763
39 Android Get Phone Contacts details with Contact Image admin 2013-12-15 13855
38 안드로이드 커스텀 타이틀바 How to add custom title bar to android application admin 2013-10-02 17034
» How to create a custom title bar admin 2013-07-15 15464