Android code controls the style of the Seekbar

Source: Internet
Author: User
<span id="Label3"></p><pre><span style="color: #0000ff;"><span style="color: #0000ff;"></span> package</span><span style="color: #000000;"><span style="color: #000000;">com.zte;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.app.Activity;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.graphics.Color;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.graphics.drawable.ClipDrawable;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.graphics.drawable.Drawable;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.graphics.drawable.GradientDrawable;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.graphics.drawable.LayerDrawable;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.os.Bundle;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.view.Gravity;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.widget.LinearLayout;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.widget.ProgressBar;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Import</span></span><span style="color: #000000;"><span style="color: #000000;">android.widget.SeekBar;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>Seekbaactivity<span style="color: #0000ff;"><span style="color: #0000ff;">extends</span></span><span style="color: #000000;"><span style="color: #000000;">Activity {</span></span><span style="color: #008000;"><span style="color: #008000;">/**</span></span><span style="color: #008000;">Called when the activity is first <span style="color: #008000;">Created.</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onCreate (Bundle Savedinstancestate) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. OnCreate (savedinstancestate); Setcontentview (r.layout.main); SeekBar ProgressBar</span></span>=<span style="color: #000000;"><span style="color: #000000;">(SeekBar) Findviewbyid (r.id.seekbar1);p Rogressbar.setmax (</span></span>100<span style="color: #000000;"><span style="color: #000000;">);p rogressbar.setprogress (</span></span>45<span style="color: #000000;"><span style="color: #000000;">);p rogressbar.setsecondaryprogress (</span></span>50<span style="color: #000000;"><span style="color: #000000;">);p rogressbar.setthumb (getresources (). getdrawable (r.drawable.handleview_layout_seek)); Layerdrawable progressdrawable</span></span>=<span style="color: #000000;"><span style="color: #000000;">(layerdrawable) progressbar.getprogressdrawable ();D rawable[] outdrawables</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">drawable[progressdrawable.getnumberoflayers ()];</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>i = 0; I < progressdrawable.getnumberoflayers (); i++<span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Switch</span></span><span style="color: #000000;"><span style="color: #000000;">(progressdrawable.getid (I)) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> case</span>Android. R.id.background:<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Setting the progress bar background</span></span>outdrawables[i] =<span style="color: #000000;"><span style="color: #000000;">getresources (). getdrawable (r.drawable.handleview_layout_seekbar_bg);</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> break</span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> case</span>Android. R.id.secondaryprogress:<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set level two progress bar</span></span>outdrawables[i] =<span style="color: #000000;"><span style="color: #000000;">getresources (). getdrawable (r.drawable.handleview_layout_seekbar_bg);</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> break</span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> case</span>Android. R.id.progress:<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">set the progress bar</span></span>Clipdrawable oiddrawable =<span style="color: #000000;"><span style="color: #000000;">(clipdrawable) progressdrawable.getdrawable (i);D rawable drawable</span></span>=<span style="color: #000000;"><span style="color: #000000;">getresources (). getdrawable (r.drawable.handleview_layout_seekbar_fg); Clipdrawable prodrawable</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">clipdrawable (drawable,gravity.left, clipdrawable.horizontal);p rodrawable.setlevel (oidDrawable.getLevel ()); o utdrawables[i]</span></span>=<span style="color: #000000;"><span style="color: #000000;">prodrawable;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> break</span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">default</span></span><span style="color: #000000;"><span style="color: #000000;">:</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> break</span><span style="color: #000000;"><span style="color: #000000;">;}} Progressdrawable</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">layerdrawable (outdrawables);p rogressbar.setprogressdrawable (progressdrawable);}}</span></span></pre><p><p></p></p><p><p>Android code controls the style of the Seekbar</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.