我想制作自定义吐司,点击按钮后会弹出搜索栏。
自定义吐司中的搜索栏出现,但搜索栏的进度无法移动。
这就是它的外观
对于代码,这是 seekbar 的活动。
package com.example.froyo2;
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
public class BloodpressureActivity extends Activity implements OnSeekBarChangeListener{
private SeekBar bar; // declare seekbar object variable
// declare text label objects
private TextView textProgress,textAction;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bloodpressure);
bar = (SeekBar)findViewById(R.id.seekBar1);
bar.setOnSeekBarChangeListener(this);
textProgress = (TextView) findViewById(R.id.textViewProgress);
textAction = (TextView) findViewById(R.id.textViewAction);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// change progress text label with current seekbar value
textProgress.setText("The value is: "+progress);
Toast.makeText(this, "Progress: " +progress, 2500).show();
// change action text label to changing
textAction.setText("changing");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
textAction.setText("starting to track touch");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
seekBar.setSecondaryProgress(seekBar.getProgress());
textAction.setText("ended tracking touch");
}
}
这是按钮的侦听器,单击按钮后它将显示自定义吐司。
public void onClick(View v){
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.bloodpressure, (ViewGroup) findViewById(R.id.seekBar1));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}