Android custom title and androidtitle
Package com. xiangyu. su; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. view. viewGroup. layoutParams; import android. widget. button; import android. widget. frameLayout; import android. widget. textView; import android. widget. toast; public class BasicActivity extends Activity implements OnClickListener {private TextView mTitl ETextView; private Button mBackwardButton; private Button mForwardButton; private FrameLayout mContentLayout; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setupViews ();} private void setupViews () {super. setContentView (R. layout. activity_title); mTitleTextView = (TextView) findViewById (R. id. text_title); mContentLayout = (FrameLayout) findViewById (R. id. layout_co Ntent); mBackwardButton = (Button) findViewById (R. id. button_backward); mForwardButton = (Button) findViewById (R. id. button_forward); mBackwardButton. setOnClickListener (this); mForwardButton. setOnClickListener (this);} protected void showBackwardView (int backwardResid, boolean show) {if (mBackwardButton! = Null) {if (show) {mBackwardButton. setText (backwardResid); mBackwardButton. setVisibility (View. VISIBLE);} else {mBackwardButton. setVisibility (View. INVISIBLE) ;}} protected void showForwardView (int forwardResid, boolean show) {if (mForwardButton! = Null) {if (show) {mForwardButton. setVisibility (View. VISIBLE); mForwardButton. setText (forwardResid);} else {mForwardButton. setVisibility (View. INVISIBLE) ;}} private void onBackward (View backwardView) {Toast. makeText (this, "Return", Toast. LENGTH_SHORT ). show ();} protected void onForward (View forwardView) {Toast. makeText (this, "Submit", Toast. LENGTH_LONG ). show () ;}@ Override public void setTitle (int titleId) {mTitleTextView. setText (titleId) ;}@ Override public void setTitle (CharSequence title) {mTitleTextView. setText (title) ;}@ Override public void setTitleColor (int textColor) {mTitleTextView. setTextColor (textColor) ;}@ Override public void setContentView (int layoutResID) {mContentLayout. removeAllViews (); View. inflate (this, layoutResID, mContentLayout); onContentChanged () ;}@ Override public void setContentView (View view) {mContentLayout. removeAllViews (); mContentLayout. addView (view); onContentChanged ();}/* (non-Javadoc) * @ see android. app. activity # setContentView (android. view. view, android. view. viewGroup. layoutParams) */@ Override public void setContentView (View view, LayoutParams params) {mContentLayout. removeAllViews (); mContentLayout. addView (view, params); onContentChanged () ;}@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. button_backward: onBackward (v); break; case R. id. button_forward: onForward (v); break; default: break ;}}}
<?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="match_parent" android:orientation="vertical" > <include layout="@layout/layout_titlebar"/> <FrameLayout android:id="@+id/layout_content" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFF"> </FrameLayout></LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/layout_titlebar" android: layout_width = "match_parent" android: layout_height = "52dp" android: background = "# ed4255"> <TextView android: id = "@ + id/text_title" android: layout_width = "match_parent" android: layout_height = "match_parent" android: gravity = "center_horizontal | center" android: singleLine = "true" android: text = "title bar" android: textColor = "# ffffffff" android: textSize = "20dp"/> <Button android: id = "@ + id/button_backward" android: layout_width = "60dp" android: layout_height = "match_parent" android: background = "@ drawable/title_button_selector" android: drawableLeft = "@ mipmap/back_arrow" android: drawablePadding = "6dp" android: gravity = "center" android: paddingLeft = "5dp" android: singleLine = "true" android: text = "back" android: textColor = "# ffffff" android: textSize = "18dp" android: visibility = "invisible"/> <Button android: id = "@ + id/button_forward" android: layout_width = "60dp" android: layout_height = "match_parent" android: layout_alignParentRight = "true" android: background = "@ drawable/title_button_selector" android: drawablePadding = "6dp" android: gravity = "center" android: paddingLeft = "5dp" android: singleLine = "true" android: text = "" android: textColor = "# ffffff" android: textSize = "18dp" android: visibility = "invisible"/> </RelativeLayout>
Usage:
Inherit this activity and override the onclick () method.