android 自訂title,androidtitle

來源:互聯網
上載者:User

android 自訂title,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 mTitleTextView;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_content);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, "返回", Toast.LENGTH_SHORT).show();}protected void onForward(View forwardView) {        Toast.makeText(this, "提交", 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="標題列"        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="返回"    android:textColor="#ffffffff"    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="#ffffffff"    android:textSize="18dp"    android:visibility="invisible"/></RelativeLayout>

  使用方法:

繼承這個activity,重寫onclick()方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.