DIỄN ĐÀN TIN HOC
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
DIỄN ĐÀN TIN HOC

BÀI VIẾT MỚINGƯỜI GỬI CUỐI

      Thảo luận nhiều nhất

      Lượt xem nhiều nhất


      You are not connected. Please login or register

      [Android] ToggleButton

         

      nhuvannhu

      #1[Android] ToggleButton Empty Thu May 29, 2014 11:57 am

      nhuvannhu
      nhuvannhu Quản lý viên

      Giới tính : Nam

      Tổng số bài gửi Tổng số bài gửi : 18

      Points Points : 57

      Like Like : 3

      status : Không có gì để nói

      Project demo [You must be registered and logged in to see this link.]
      [Android] ToggleButton HhPDv4E
      ActivityToggleButton.java
      Code:
      import android.os.Bundle;
      import android.app.Activity;
      import android.content.Intent;
      import android.util.Log;
      import android.view.Menu;
      import android.widget.CompoundButton;
      import android.widget.Switch;
      import android.widget.CompoundButton.OnCheckedChangeListener;
      import android.widget.ToggleButton;

      public class ActivityToggleButton extends Activity {
         private ToggleButton toggleButton;
         

         @Override
         protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_toggle_button);
            toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
            toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
               
               @Override
               public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
               
                  // TODO Auto-generated method stub
                  if(arg1){
                  
                     Intent intent = new Intent(ActivityToggleButton.this,ActivityToggleButton2.class);
                     startActivity(intent);
                     overridePendingTransition(R.anim.animation_down_enter, R.anim.animation_down_exit);
                  }
                  else{
                     
                  }
               }
            });
         }



      }
      AcitivityToggleButton2.java
      Spoiler:
      activity_toggle_button.xml
      Code:
      <LinearLayout 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:gravity="center"
          android:orientation="horizontal"
          tools:context=".ActivityToggleButton" >

          <ToggleButton
              android:id="@+id/toggleButton1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@null"
              android:button="@null"
              android:textOn="@null"
              android:textOff="@null"
              android:background="@drawable/btntoggle" />

      </LinearLayout>
      activity_toggle_button2.xml
      Spoiler:
      animation_down_enter.xml
      Code:
      <?xml version="1.0" encoding="utf-8"?> 
      <set xmlns:android="http://schemas.android.com/apk/res/android"
          android:interpolator="@android:anim/linear_interpolator"> 
        <translate
            android:fromYDelta="-100%p"
            android:toYDelta="0%p"
            android:duration="500"/>
      </set>
      Các anim còn lại thì trong project demo đã có rồi.
         
            

      [Trang 1 trong tổng số 1 trang]

      Thông tin chuyên mục

      Bạn không có quyền trả lời bài viết