改寫BEAR  原始參考自  邵洋江的博客
                                                                                   //實作Seek介面
public class MainActivity extends Activity implements OnSeekBarChangeListener{
              private  SeekBar redColor,greenColor,blueColor;
              private  RelativeLayout  layout;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  findView();
 }
public void findView(){ 
     redColor=(SeekBar)findViewById(R.id.redColor);
  greenColor=(SeekBar)findViewById(R.id.greenColor);
  blueColor=(SeekBar)findViewById(R.id.blueColor);
  layout=(RelativeLayout)findViewById(R.id.layout);
  
  //綁定
  greenColor.setOnSeekBarChangeListener((OnSeekBarChangeListener)this);
  blueColor.setOnSeekBarChangeListener((OnSeekBarChangeListener)this);
  redColor.setOnSeekBarChangeListener((OnSeekBarChangeListener)this);
   }

    //拖曳
   public void onProgressChanged(SeekBar seekbar2,int progress, boolean fromTouch){
       int r = redColor.getProgress();
       int g = greenColor.getProgress();
       int b = blueColor.getProgress();
       layout.setBackgroundColor(Color.rgb(r, g, b));

    }
      //開始
       public  void onStartTrackingTouch (SeekBar seekbar){
      
      }
      //停止
      public void onStopTrackingTouch (SeekBar seekbar){
         String msg=getString(R.string.rgbcolor)+"( "+redColor.getProgress()+"."
                                                                                 +greenColor.getProgress()+"."
                                                                                 +blueColor.getProgress()+" )";
        Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
      }
  }

佈署

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:id="@+id/layout"
    tools:context="${packageName}.${activityClass}" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="16dp"
        android:text="@string/Reds"
        android:textColor="@color/red" />

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/blueColor"
        android:layout_alignLeft="@+id/TextView01"
        android:text="@string/Blue"
        android:textColor="@color/blue" />

    <SeekBar
        android:id="@+id/redColor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView3"
        android:clickable="@bool/abc_action_bar_embed_tabs_pre_jb"
        android:longClickable="@bool/abc_config_showMenuShortcutsWhenKeyboardPresent"
        android:max="255"
        android:minHeight="20dip"
        android:progress="0" />

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/greenColor"
        android:layout_alignLeft="@+id/textView3"
        android:text="@string/Green"
        android:textColor="@color/green" />

    <SeekBar
        android:id="@+id/greenColor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/TextView02"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="39dp"
        android:clickable="@bool/abc_action_bar_embed_tabs_pre_jb"
        android:longClickable="@bool/abc_config_showMenuShortcutsWhenKeyboardPresent"
        android:max="255"
        android:minHeight="20dip"
        android:progress="0" />

    <SeekBar
        android:id="@+id/blueColor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:clickable="@bool/abc_action_bar_embed_tabs_pre_jb"
        android:longClickable="@bool/abc_config_showMenuShortcutsWhenKeyboardPresent"
        android:max="255"
        android:minHeight="20dip"
        android:progress="0" />

</RelativeLayout>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 OK熊 的頭像
    OK熊

    OK熊 碼農時代

    OK熊 發表在 痞客邦 留言(0) 人氣()