Android实现开关灯效果-创新互联

Android  实现开关灯效果

创新互联专注于洛隆网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供洛隆营销型网站建设,洛隆网站制作、洛隆网页设计、洛隆网站官网定制、小程序制作服务,打造洛隆网络公司原创品牌,更为您提供洛隆网站排名全网营销落地服务。成都创新互联公司专注于且末网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供且末营销型网站建设,且末网站制作、且末网页设计、且末网站官网定制、小程序开发服务,打造且末网络公司原创品牌,更为您提供且末网站排名全网营销落地服务。成都创新互联专注于海原网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供海原营销型网站建设,海原网站制作、海原网页设计、海原网站官网定制、重庆小程序开发服务,打造海原网络公司原创品牌,更为您提供海原网站排名全网营销落地服务。创新互联专注于清涧网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供清涧营销型网站建设,清涧网站制作、清涧网页设计、清涧网站官网定制、重庆小程序开发服务,打造清涧网络公司原创品牌,更为您提供清涧网站排名全网营销落地服务。

Android  实现开关灯效果

activity_main.xml

  xmlns:tools="http://schemas.android.com/tools"

  android:id="@+id/linear_1"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="horizontal" >

  

    android:id="@+id/p_w_picpath_1"

    android:layout_width="150dp"

    android:layout_height="150dp"

    android:contentDescription="@string/deng"

    android:src="@drawable/bulb_off"

    android:text="@string/hello_world" />

  

    android:id="@+id/linear_2"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:orientation="vertical"

    android:paddingLeft="10dip"

    android:paddingTop="10dip" >

    

      android:id="@+id/toggle"

      android:layout_width="140dip"

      android:layout_height="wrap_content"

      android:textOff="@string/off"

      android:textOn="@string/on" />

    

      android:id="@+id/radio_1"

      android:layout_width="wrap_content"

      android:layout_height="wrap_content"

      android:orientation="horizontal" >

      

        android:id="@+id/button_off"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:checked="true"

        android:text="@string/off" />

      

        android:id="@+id/button_on"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="@string/on" />

    

    

      android:id="@+id/check"

      android:layout_width="wrap_content"

      android:layout_height="wrap_content"

      android:text="@string/on" />

  

string.xml

  ToggleButton

  Settings

  Hello world!

  

  开灯

  关灯

MainActivity.java

package com.malakana.togglebutton;

import android.os.Bundle;

import android.widget.CheckBox;

import android.widget.CompoundButton;

import android.widget.CompoundButton.OnCheckedChangeListener;

import android.widget.ImageView;

import android.widget.RadioButton;

import android.widget.ToggleButton;

import android.app.Activity;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ToggleButton tb = (ToggleButton) findViewById(R.id.toggle);

tb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

// TODO Auto-generated method stub

setBulbState(arg1);

}

});

CheckBox cb = (CheckBox) this.findViewById(R.id.check);

cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

// TODO Auto-generated method stub

setBulbState(arg1);

}

});

RadioButton rb = (RadioButton) findViewById(R.id.button_off);

rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

// TODO Auto-generated method stub

setBulbState(!arg1);

}

});

}

public void setBulbState(boolean state) {

// TODO Auto-generated method stub

ImageView iv = (ImageView) findViewById(R.id.p_w_picpath_1);

iv.setImageResource((state) ? R.drawable.bulb_on : R.drawable.bulb_off);

ToggleButton tb = (ToggleButton) findViewById(R.id.toggle);

tb.setChecked(state);

CheckBox cb = (CheckBox) findViewById(R.id.check);

//cb.setText((state) ? R.string.on : R.string.off);

cb.setChecked(state);

RadioButton rb = (RadioButton) findViewById(R.id.button_off);

rb.setChecked(!state);

rb = (RadioButton) findViewById(R.id.button_on);

rb.setChecked(state);

}

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:Android实现开关灯效果-创新互联
本文URL:http://myzitong.com/article/cehses.html