Android
CustomTitlebar 재활용
그란.
2017. 11. 20. 10:36
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, "현재 영업중인 트럭");