Android在Activity设置调节音量的代码不管用
如下代码所示,我在setContentView的参数为一个View的Activity中调用管理音量的代码不管用,而在另一个setContentView的参数为一个layout的活动中是有效的。请问这是为什么?以及怎样来解决?不胜感激。
package com.mario.load;
import com.mario.menu.MenuActivity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.KeyEvent;
import game.activity.GameActivity;
public class LoadActivity extends GameActivity implements Runnable
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
new Thread(this).start();
this.SetScreenToFull();
this.GetScreenSize();
super.onCreate(savedInstanceState);
super.setContentView(new LoadView(this));
}
@Override
public void run()
{
LoadResource.LoadImage(this);
LoadResource.LoadMusic(this);
Intent i = new Intent(this,MenuActivity.class);
this.startActivity(i);
this.finish();
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
this.finish();
}
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
switch (keyCode) {
// 音量减小
case KeyEvent.KEYCODE_VOLUME_DOWN:
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_LOWER,
AudioManager.FX_FOCUS_NAVIGATION_UP);
// 音量减小时应该执行的功能代码
return true;
// 音量增大
case KeyEvent.KEYCODE_VOLUME_UP:
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_RAISE,
AudioManager.FX_FOCUS_NAVIGATION_UP);
// 音量增大时应该执行的功能代码
return true;
}
return true;
}
}
package com.mario.load;
import com.mario.menu.MenuActivity;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.KeyEvent;
import game.activity.GameActivity;
public class LoadActivity extends GameActivity implements Runnable
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
new Thread(this).start();
this.SetScreenToFull();
this.GetScreenSize();
super.onCreate(savedInstanceState);
super.setContentView(new LoadView(this));
}
@Override
public void run()
{
LoadResource.LoadImage(this);
LoadResource.LoadMusic(this);
Intent i = new Intent(this,MenuActivity.class);
this.startActivity(i);
this.finish();
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
this.finish();
}
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
switch (keyCode) {
// 音量减小
case KeyEvent.KEYCODE_VOLUME_DOWN:
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_LOWER,
AudioManager.FX_FOCUS_NAVIGATION_UP);
// 音量减小时应该执行的功能代码
return true;
// 音量增大
case KeyEvent.KEYCODE_VOLUME_UP:
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_RAISE,
AudioManager.FX_FOCUS_NAVIGATION_UP);
// 音量增大时应该执行的功能代码
return true;
}
return true;
}
}
没有找到相关结果
已邀请:
2 个回复
lzan13 - 慢慢来,一步一个脚印?
赞同来自: 逄淑越
逄淑越
赞同来自: fat1