搜索栏编程 [英] SeekBar programmatically

查看:207
本文介绍了搜索栏编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个搜索栏编程方式是这样的:

I am creating a SeekBar programmatically like this :

SeekBar seekBar = new SeekBar(this);
seekBar.setMax(15);
seekBar.setIndeterminate(true);
seekBar.setMinimumWidth(200);

ShapeDrawable thumb = new ShapeDrawable(new OvalShape());

thumb.getPaint().setColor(0x00FF00);
thumb.setIntrinsicHeight(80);
thumb.setIntrinsicWidth(30);

seekBar.setThumb(thumb);
seekBar.setProgress(1);

但所有我能看到的是一个小的搜索栏
可能是什么问题?

But what all I am able to see is a small SeekBar.
What might be the problem?

感谢

推荐答案

尝试使用以下code

Try with the following code

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class Sample2 extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        SeekBar seekBar = new SeekBar(this);
        seekBar.setMax(15);
//      seekBar.setIndeterminate(true);

        ShapeDrawable thumb = new ShapeDrawable(new OvalShape());

        thumb.setIntrinsicHeight(80);
        thumb.setIntrinsicWidth(30);
        seekBar.setThumb(thumb);
        seekBar.setProgress(1);
        seekBar.setVisibility(View.VISIBLE);
        seekBar.setBackgroundColor(Color.BLUE);

        LayoutParams lp = new LayoutParams(200, 50);
        seekBar.setLayoutParams(lp);
        seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            public void onStopTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub
                System.out.println(".....111.......");

            }

            public void onStartTrackingTouch(SeekBar arg0) {
                // TODO Auto-generated method stub
                System.out.println(".....222.......");
            }

            public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
                // TODO Auto-generated method stub
                System.out.println(".....333......."+arg1);
            }
        });
        setContentView(seekBar);
    }
}

谢谢 迪帕克

Thanks Deepak

这篇关于搜索栏编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆