TabHost + PreferenceActivity

src/com/example.hellotabhost/HelloTabHost.java

package com.example.hellotabhost;

import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.TabActivity;
import android.content.Intent;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;

@SuppressLint("NewApi")
public class HelloTabHost extends TabActivity {
	private static final String TAG = "HelloTabHost";
	private TabHost mtabHost;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mtabHost = getTabHost(); 
		mtabHost.addTab(mtabHost.newTabSpec("tab1")
				.setIndicator(getString(R.string.tabs_1_tab_1), getResources().getDrawable(R.drawable.ic_launcher)) 
				.setContent(new Intent(this, A_Activity.class))); 
		mtabHost.addTab(mtabHost.newTabSpec("tab2")
				.setIndicator(getString(R.string.tabs_1_tab_2),getResources().getDrawable(R.drawable.ic_launcher)) 
				.setContent(new Intent(this, B_Activity.class))); 
		
		//
		final TabWidget tabWidget = mtabHost.getTabWidget();


		for (int i = 0; i < tabWidget.getChildCount(); i++) {
            tabWidget.getChildAt(i).getLayoutParams().height = 98;  //设置Tab高度
            tabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_bg);	//设置Tab项背景色

            //设置Tab的字体的大小和颜色
            TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
            tv.setTextSize(20);
            tv.setTextColor(this.getResources().getColorStateList(android.R.color.white));

        }
	}

}
src/com/example.hellotabhost/A_Activity .java
package com.example.hellotabhost;

import java.util.List;
import android.os.Bundle;
import android.preference.PreferenceActivity;

public class A_Activity extends PreferenceActivity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onBuildHeaders(List<Header> target) {
		loadHeadersFromResource(R.xml.preference_headers, target);
	}
}

res/xml/preference_headers.xml

<preference-headers
        xmlns:android="http://schemas.android.com/apk/res/android">

    <header 
            android:icon="@drawable/wind_wlan"
            android:title="@string/wlan"/>
    <header 
            android:icon="@drawable/wind_display"
            android:title="@string/brightness">
            <intent android:action="my.intent.action.BRIGHTNESS" />
    </header>

    <header android:icon="@drawable/wind_sound"
            android:title="@string/volumn">
            <intent android:action="my.intent.action.VOLUMN" />
    </header>
    
    <header android:icon="@drawable/wind_date"
            android:title="@string/date_time">
    </header>
    
    <header android:icon="@drawable/wind_display"
            android:title="@string/font">
            <intent android:action="my.intent.action.FONT" />
    </header>
    
    <header android:icon="@drawable/wind_application"
            android:title="@string/auto_rotation">
    </header>
    
    <header android:icon="@drawable/wind_storage"
            android:title="@string/standby"
            android:summary="@string/standby_sumary" >
            <intent android:action="com.example.hellotabhost.B_Activity"/>
    </header>

    <header android:icon="@drawable/wind_battery"
            android:title="Intent"
            android:summary="Launches an Intent.">
        <intent android:action="android.intent.action.VIEW"
                android:data="http://www.android.com" />
    </header>
</preference-headers>
src/com/example.hellotabhost/FontDialog .java
package com.example.hellotabhost;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * This example shows how to use choice mode on a list. This list is 
 * in CHOICE_MODE_SINGLE mode, which means the items behave like
 * checkboxes.
 */
public class FontDialog extends ListActivity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final ListView listView = getListView();
        setTitle("字体大小");
        TextView cancel = new TextView(this);
        cancel.setText("取消");
        cancel.setTextSize(20);
        cancel.setHeight(80);
        cancel.setGravity(Gravity.CENTER);
        
        cancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
        listView.addFooterView(cancel);
        
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_single_choice, GENRES));
        
        listView.setItemsCanFocus(false);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        this.setFinishOnTouchOutside(false);
    }

    @Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		finish();
	}

	private static final String[] GENRES = new String[] {
        "小", "普通", "大", "超大"
    };
}
src/com/example.hellotabhost/BrightnessDialog.java
package com.example.hellotabhost;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.SeekBar;
import android.widget.TextView;

public class BrightnessDialog extends Activity implements OnClickListener, SeekBar.OnSeekBarChangeListener{
	private static final String TAG = "BrightnessDialog";
	private TextView mCancel;
	private TextView mOK;
	private SeekBar mSeekBar;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_LEFT_ICON);
		setTitle("亮度");
		setContentView(R.layout.brightness);
		getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
                R.drawable.wind_display);
		mSeekBar = (SeekBar)findViewById(R.id.seek);
		mCancel = (TextView) this.findViewById(R.id.cancel);
		mOK = (TextView) this.findViewById(R.id.ok);
		
		mSeekBar.setOnSeekBarChangeListener(this);
		mCancel.setOnClickListener(this);
		mOK.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.cancel:
			finish();
			break;
			
		case R.id.ok:
			finish();
			break;
		default:
			break;
		}
		
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress,
			boolean fromUser) {
		Log.v(TAG, "onProgressChanged progress = " + progress);
		Log.v(TAG, "onProgressChanged fromUser = " + fromUser);
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		Log.v(TAG, "onStartTrackingTouch");
		
	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		Log.v(TAG, "onStopTrackingTouch");
	}
}
src/com/example.hellotabhost/VolumnDialog .java
package com.example.hellotabhost;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.SeekBar;
import android.widget.TextView;

public class VolumnDialog extends Activity implements OnClickListener, SeekBar.OnSeekBarChangeListener{
	private TextView mCancel;
	private TextView mOK;
	private SeekBar mPhoneSeekBar;
	private SeekBar mAlarmSeekBar;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_LEFT_ICON);
		setTitle("音量");
		setContentView(R.layout.volumn);
		getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
                R.drawable.wind_sound);
		
		mCancel = (TextView) this.findViewById(R.id.cancel);
		mOK = (TextView) this.findViewById(R.id.ok);
		mPhoneSeekBar = (SeekBar)findViewById(R.id.seek_phone);
		mAlarmSeekBar = (SeekBar)findViewById(R.id.seek_alarm);
		
		mPhoneSeekBar.setOnSeekBarChangeListener(this);
		mAlarmSeekBar.setOnSeekBarChangeListener(this);
		mCancel.setOnClickListener(this);
		mOK.setOnClickListener(this);
	}

	@Override
	public void onProgressChanged(SeekBar seekbar, int process, boolean fromuser) {
		switch (seekbar.getId()) {
		case R.id.seek_phone:
			break;
		case R.id.seek_alarm:
			break;
		default:
			break;
		}
		
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub	
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.cancel:
			finish();
			break;
			
		case R.id.ok:
			finish();
			break;
		default:
			break;
		}
		
	}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.hellotabhost"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.hellotabhost.HelloTabHost"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.hellotabhost.A_Activity"></activity>
        <activity android:name="com.example.hellotabhost.B_Activity">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>    
        </activity>
	<activity
            android:name="com.example.hellotabhost.FontDialog"
            android:theme="@style/DialogTheme" >
            <intent-filter>
                <action android:name="my.intent.action.FONT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>   
        </activity>
        
        <activity
            android:name="com.example.hellotabhost.BrightnessDialog"
            android:theme="@style/DialogTheme" >
            <intent-filter>
                <action android:name="my.intent.action.BRIGHTNESS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>   
        </activity>
        
        <activity
            android:name="com.example.hellotabhost.VolumnDialog" 
            android:theme="@style/DialogTheme">
            <intent-filter>
                <action android:name="my.intent.action.VOLUMN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>   
        </activity>
    </application>

</manifest>
res/layout/brightness.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SeekBar android:id="@+id/seek"
        android:paddingTop="20dip"
        android:paddingBottom="30dip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50"
        android:secondaryProgress="75" />
	<View android:layout_width="match_parent"
	    android:layout_height="1dip"
	    android:background="@android:color/holo_blue_light"
	    />
    <LinearLayout
	    android:orientation="horizontal"
	    android:layout_width="match_parent"
	    android:layout_height="50dip">
	    <TextView android:id="@+id/cancel"
	        android:text="取消"
	        android:textSize="20sp"
	        android:gravity="center"
	       	android:layout_width="match_parent"
	        android:layout_height="match_parent"
	        android:layout_weight="1" />
	    
		<View android:layout_width="0.5dip"
	    android:layout_height="match_parent"
	    android:background="@android:color/black" />
	    
	    <TextView android:id="@+id/ok"
	        android:text="确定"
	        android:textSize="20sp"
	        android:gravity="center"
	       	android:layout_width="match_parent"
	        android:layout_height="match_parent"
	        android:layout_weight="1" />
	</LinearLayout>
</LinearLayout>
res/layout/volumn.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView 
	        android:text="铃声和通知"
	        android:textSize="20sp"
	       	android:layout_width="match_parent"
	        android:layout_height="wrap_content"
	        android:paddingLeft="5dip"/>
    
    <LinearLayout
	    android:orientation="horizontal"
	    android:layout_width="match_parent"
	    android:layout_height="wrap_content">
	    <ImageView 
	        android:src="@drawable/wind_about"
	        android:layout_width="wrap_content"
	    	android:layout_height="wrap_content"
	    	android:paddingTop="20dip"
	    	android:paddingLeft="10dip"
	    	android:paddingBottom="30dip"
	        />
	    <SeekBar android:id="@+id/seek_phone"
	        android:paddingTop="20dip"
	        android:paddingBottom="30dip"
	        android:layout_width="match_parent"
	        android:layout_height="wrap_content"
	        android:max="100"
	        android:progress="50"
	        android:secondaryProgress="75" />
    </LinearLayout>
    
    <TextView 
	        android:text="闹钟"
	        android:textSize="20sp"
	       	android:layout_width="match_parent"
	        android:layout_height="wrap_content"
	        android:paddingLeft="5dip"/>
    
    <LinearLayout
	    android:orientation="horizontal"
	    android:layout_width="match_parent"
	    android:layout_height="wrap_content">
	    <ImageView 
	        android:src="@drawable/wind_date"
	        android:layout_width="wrap_content"
	    	android:layout_height="wrap_content"
	    	android:paddingTop="20dip"
	    	android:paddingLeft="10dip"
	    	android:paddingBottom="30dip"
	        />
	    
	    <SeekBar android:id="@+id/seek_alarm"
	        android:paddingTop="20dip"
	        android:paddingBottom="30dip"
	        android:layout_width="match_parent"
	        android:layout_height="wrap_content"
	        android:max="100"
	        android:progress="50"
	        android:secondaryProgress="75" />
    </LinearLayout>
    
	<View android:layout_width="match_parent"
	    android:layout_height="1dip"
	    android:background="@android:color/holo_blue_light"
	    />
    <LinearLayout
	    android:orientation="horizontal"
	    android:layout_width="match_parent"
	    android:layout_height="50dip">
	    <TextView android:id="@+id/cancel"
	        android:text="取消"
	        android:textSize="20sp"
	        android:gravity="center"
	       	android:layout_width="match_parent"
	        android:layout_height="match_parent"
	        android:layout_weight="1" />
	    
		<View android:layout_width="0.5dip"
	    android:layout_height="match_parent"
	    android:background="@android:color/black" />
	    
	    <TextView android:id="@+id/ok"
	        android:text="确定"
	        android:textSize="20sp"
	        android:gravity="center"
	       	android:layout_width="match_parent"
	        android:layout_height="match_parent"
	        android:layout_weight="1" />
	</LinearLayout>
</LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值