MainActivity.java
package com.example.a;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.os.Build;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actionbar_tab);
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false); //隐藏icon
actionBar.setDisplayShowHomeEnabled(false); //隐藏标题
alistAction alist = new alistAction();
Tab tab1 = actionBar.newTab();
tab1.setText("列表");
tab1.setIcon(R.drawable.ic_launcher);
tab1.setTabListener(new ListenerA(alist));
actionBar.addTab(tab1);
Button btnCall=(Button)findViewById(R.id.tbnCall);
btnCall=(Button) findViewById(R.id.tbnCall);
btnCall.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
startActivity(new Intent(Intent.ACTION_CALL,Uri.parse("tel://10086")));
}
});
}
private class ListenerA implements ActionBar.TabListener {
private alistAction alist;
public ListenerA(alistAction fragment) {
alist = fragment;
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.add(R.id.fragment_content, alist, null);
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(alist);
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
}
}
actionbar_tab.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
alist.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imgHead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imgHead"
android:layout_centerHorizontal="false"
android:layout_toRightOf="@+id/imgHead"
android:text="Name" />
<TextView
android:id="@+id/txtPhome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imgHead"
android:layout_centerHorizontal="false"
android:layout_toRightOf="@+id/imgHead"
android:text="Phone" />
<Button
android:id="@+id/tbnCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/txtName"
android:layout_marginLeft="75dp"
android:layout_toRightOf="@+id/txtName"
android:text="拨号" />
</RelativeLayout>
alistAction
package com.example.a;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.zip.Inflater;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class alistAction extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View image = inflater.inflate(R.layout.alist, container,
false);
return image;
}
}