0
我一直在玩這個偏好活動代碼,現在大部分時間都在這裏,並且在我最後一篇文章中提供了一些幫助,所以我將它編譯/安裝在AVD上,但它不會運行,並且不會顯示在應用程序菜單中。下面是代碼:Android:首選活動未運行?
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
public class volman extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dhd);
DialogPreference dp = (DialogPreference) findPreference("mediavolume");
dp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference,
Object newValue) {
SeekBar volumeBar = (SeekBar) findViewById(R.id.seekBar);
final AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
volumeBar.setMax(manager
.getStreamMaxVolume(AudioManager.STREAM_SYSTEM));
volumeBar.setProgress(manager
.getStreamVolume(AudioManager.STREAM_SYSTEM));
volumeBar
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(volman.this, "Starting Vol Tracking", Toast.LENGTH_LONG).show();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(volman.this, "Now Stopping", Toast.LENGTH_LONG).show();
}
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
manager.setStreamVolume(
AudioManager.STREAM_SYSTEM, progress,
AudioManager.FLAG_SHOW_UI);
Toast.makeText(volman.this, "Now going Silent!", Toast.LENGTH_LONG).show();
}
});
return false;
}
});
}
private DialogPreference findPreference(String string) {
return null;
}
}
這裏是清單文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="path.to.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".volman"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.PREFERENCE" />
</intent-filter>
</activity>
</application>
是的,我相信。 – 2012-07-06 20:45:11
@ a.kollar那麼,那是否回答你的問題? – 2012-07-07 08:29:04
不,它沒有回答這個問題,我可能會重新發布並獲得不同的觀點。 – 2012-07-07 15:17:06