只需将以下代码放在您的TabHost
主要活动中 -
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
ImageView image = (ImageView)findViewById(R.id.header);
image.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast.makeText(CustomWindowTitle.this, "This is sample", Toast.LENGTH_SHORT).show();
return false;
}
});
}
窗口标题.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:id="@+id/header"
android:src="@drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
希望这对您有所帮助。请参阅下面的输出 -
更新
我知道了。OnclickListener
在图像对代码进行如下更改后,您已声明您的自定义标题-
public class MyCustomTab2Activity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//Tab Content
setContentView(R.layout.my_tab_home);
//custom title bar content
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.logintitle);
ImageView imag = (ImageView) findViewById(R.id.iv_logout);
imag.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
}
});
......
...........
}
}
希望这对您有所帮助。