我创建按钮来更改音量,我希望onClick
,seekbar
显示为dialog
(但不是涵盖的那种屏幕,并且不允许与按钮下方的屏幕上的其他元素进行交互)几秒后它会消失。我不想使用 android {<1}} strong>提供涵盖整个活动。如何解决这个问题?也有任何图书馆来实现这个目标吗?
答案 0 :(得分:1)
您可以使用WindowManager
将SeekBar
添加到窗口中,同时也可以与您的活动或其他活动进行互动。发布一个处理程序以在指定时间后删除该视图。
View yourSeekBarView = inflator.inflate(R.layout.your_layout_xml,null,false);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
150,
50,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
0 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.CENTER_HORIZONTAL |Gravity.TOP;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(oView, params);
wm.removeView(yourSeekBarView);
答案 1 :(得分:1)
将您的搜索栏放在xml布局中的按钮下方,使用alpha =&#34; 0&#34;,然后尝试:
SeekBar mSeekbar;
int delay = 1000;
Button mButton;
Handler mHandler;
Runnable mRunnable = new Runnable() {
@Override
public void run() {
Animation anim = new AlphaAnimation(1, 0);
anim.setDuration(500);
mSeekbar.startAnimation(anim);
}
};
//inside onCreate (or wherever you decide)
mHandler = new Handler(); //(android.os)
mButton = (Button) findViewById(R.id.button1);
mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
mHandler.removeCallbacks(mRunnable);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.postDelayed(mRunnable, delay);
}
});
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mSeekbar.getAlpha() == 0) {
Animation anim = new AlphaAnimation(0, 1);
anim.setDuration(500);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
mHandler.postDelayed(mRunnable, delay);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mSeekbar.startAnimation(anim);
}
}
});