12345678910111213141516171819202122 public class CustomTitlebar {TextView tv_titlebar;ImageView iv_arrow_back;public Activity activity;public CustomTitlebar(Activity _activity, String title) {activity = _activity;tv_titlebar = (TextView) activity.findViewById(R.id.tv_titlebar);iv_arrow_back = (ImageView) activity.findViewById(R.id.iv_arrow_back);tv_titlebar.setText(title);iv_arrow_back.setVisibility(View.VISIBLE);iv_arrow_back.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {activity.finish();}});}}cs
layout_titlebar.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_titlebar" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentTop="true" android:background="#65B5A5" android:gravity="center" android:padding="8dp" android:text="Move To Diner" android:textColor="#FFF" android:textSize="20dp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/tv_titlebar" android:background="#D0D0D0" /> <ImageView android:id="@+id/iv_arrow_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_margin="5dp" android:padding="10dp" android:src="@drawable/ic_arrow_back" android:visibility="gone" /> </RelativeLayout> | cs |
레이아웃
<include layout="@layout/layout_titlebar" />
new CustomTitlebar(this, "현재 영업중인 트럭");
'Android' 카테고리의 다른 글
GridLayoutManager + Spacing (0) | 2017.11.20 |
---|---|
두번 누르면 종료 (0) | 2017.11.20 |
슬라이더 무한 + 자동 스크롤 + Indicator 연동 (ViewPager) (0) | 2017.11.20 |
리사이클러뷰 리스트 비었을때 EmptyView 보여주기 (0) | 2017.11.11 |
Easy Way] TedPermission + 현재 위치 -> 구글맵 (0) | 2017.11.11 |