togglebuttonandroid
Ⅰ android编程问题: ToggleButton toggleButton = (ToggleButton)this.findViewById(R.id.ToggleButton1);
两句话的意思是相同的,只不过findView把前面的this隐掉.当然可以直接使用,不会出现你所说的Edit或者Image能用,
Ⅱ android如何去掉togglebutton上面自动显示的字“on”“off”就像下面按钮上的“on”,是默认显示的。
Togglebutton通过一个带有亮度指示同时默认文本为“ON”或“OFF”的按钮显示选中/未选中状态。
提示文字的设置方式:
1.在xml中直接设置
android:textOn=""设置按钮未选中时显示的文本。
android:textOff=""设置按钮选中时显示的文本。
2.在java代码中设置:
public void setTextOff (CharSequence textOff)设置按钮未选中时显示的文本。
public void setTextOn (CharSequence textOn)设置按钮选中时显示的文本。
Ⅲ 有没有什么方法能够快速,实时的获取android手机的电量值
这个是获取android电量的DEMO:
package com.android.batterywaster;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
/**
* So you thought sync used up your battery life.
*/
public class BatteryWaster extends Activity {
TextView mLog;
DateFormat mDateFormat;
IntentFilter mFilter;
PowerManager.WakeLock mWakeLock;
SpinThread mThread;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the layout for this activity. You can find it
// in res/layout/hello_activity.xml
setContentView(R.layout.main);
findViewById(R.id.checkbox).setOnClickListener(mClickListener);
mLog = (TextView)findViewById(R.id.log);
mDateFormat = DateFormat.getInstance();
mFilter = new IntentFilter();
mFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
mFilter.addAction(Intent.ACTION_BATTERY_LOW);
mFilter.addAction(Intent.ACTION_BATTERY_OKAY);
mFilter.addAction(Intent.ACTION_POWER_CONNECTED);
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "BatteryWaster");
mWakeLock.setReferenceCounted(false);
}
@Override
public void onPause() {
stopRunning();
}
View.OnClickListener mClickListener = new View.OnClickListener() {
public void onClick(View v) {
CheckBox checkbox = (CheckBox)v;
if (checkbox.isChecked()) {
startRunning();
} else {
stopRunning();
}
}
};
void startRunning() {
log("Start");
registerReceiver(mReceiver, mFilter);
mWakeLock.acquire();
if (mThread == null) {
mThread = new SpinThread();
mThread.start();
}
}
void stopRunning() {
log("Stop");
unregisterReceiver(mReceiver);
mWakeLock.release();
if (mThread != null) {
mThread.quit();
mThread = null;
}
}
void log(String s) {
mLog.setText(mLog.getText() + "\n" + mDateFormat.format(new Date()) + ": " + s);
}
BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String title = action;
int index = title.lastIndexOf('.');
if (index >= 0) {
title = title.substring(index + 1);
}
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int icon = intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL,-1);
log(title + ": level=" + level + "\n" + "icon:" + icon);
} else {
log(title);
}
}
};
class SpinThread extends Thread {
private boolean mStop;
public void quit() {
synchronized (this) {
mStop = true;
}
}
public void run() {
while (true) {
synchronized (this) {
if (mStop) {
http://www.dewen.io/q/1428
wipe电池如下:
1、把电池充满,充满满的,在开机状态下冲到满,然后拔下充电器,手机关机,再插上充电器充电,直至再次显示充满,拔下充电器,开机再充电,这样反复几次就能把电池充到尽量满的状态。
2、然后关机,开机进入Recovery模式。
选择advanced(高级功能) -> wipe battery stats(清空电池状态)->yes(是)
然后++++ Go Back(返回上级) ++++ --> - reboot system now(重启系统) -
Ⅳ android软件开发里边 togglebutton使用setChecked问题
if (volReturned.equals("On")){
/*tbtnvol.setChecked(true);*/
tbtnvol.setSelected(boolT);
}else{
tbtnvol.setSelected(boolF);
}
if (vibReturned.equals("On")){
tbtnvib.setSelected(boolT);
}else{
tbtnvib.setSelected(boolF);
}
Ⅳ android怎么实现自动接听和挂断电话功能
android 实现来电自动接听和自动挂断的方法:
第一步:准备应用环境需要的系统包和aidl文件。
(1)在应用中创建包:android.telephony
将android系统框架下的\framework\telephony\java\android\telephony目录中的NeighboringCellInfo.aidl文件复制到上面创建的包(android.telephony )中;
(2)在应用中创建包:com.android.internal.telephony
将android系统框架下的\framework\telephony\java\com\android\internal\telephony目录中的ITelephony.aidl文件复制到上面创建的包(com.android.internal.telephony )中。
第二步:创建一个获取ITelephony的方法
PhoneUtils.java
package com.zhouzijing.android.demo;
import java.lang.reflect.Method;
import com.android.internal.telephony.ITelephony;
import android.telephony.TelephonyManager;
public class PhoneUtils {
/**
* 根据传入的TelephonyManager来取得系统的ITelephony实例.
* @param telephony
* @return 系统的ITelephony实例
* @throws Exception
*/
public static ITelephony getITelephony(TelephonyManager telephony) throws Exception {
Method getITelephonyMethod = telephony.getClass().getDeclaredMethod("getITelephony");
getITelephonyMethod.setAccessible(true);//私有化函数也能使用
return (ITelephony)getITelephonyMethod.invoke(telephony);
}
}
第三步:创建电话广播拦截器
MyPhoneBroadcastReceiver.java
package com.zhouzijing.android.demo;
import com.android.internal.telephony.ITelephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
public class MyPhoneBroadcastReceiver extends BroadcastReceiver {
private final static String TAG = MyPhone.TAG;
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.i(TAG, "[Broadcast]"+action);
//呼入电话
if(action.equals(MyPhone.B_PHONE_STATE)){
Log.i(TAG, "[Broadcast]PHONE_STATE");
doReceivePhone(context,intent);
}
}
/**
* 处理电话广播.
* @param context
* @param intent
*/
public void doReceivePhone(Context context, Intent intent) {
String phoneNumber = intent.getStringExtra(
TelephonyManager.EXTRA_INCOMING_NUMBER);
TelephonyManager telephony = (TelephonyManager)context.getSystemService(
Context.TELEPHONY_SERVICE);
int state = telephony.getCallState();
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
Log.i(TAG, "[Broadcast]等待接电话="+phoneNumber);
try {
ITelephony iTelephony = PhoneUtils.getITelephony(telephony);
iTelephony.answerRingingCall();//自动接通电话
//iTelephony.endCall();//自动挂断电话
} catch (Exception e) {
Log.e(TAG, "[Broadcast]Exception="+e.getMessage(), e);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.i(TAG, "[Broadcast]电话挂断="+phoneNumber);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i(TAG, "[Broadcast]通话中="+phoneNumber);
break;
}
}
}
第四部:注册电话广播拦截器
MyPhone.java
package com.zhouzijing.android.demo;
import android.app.Activity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
public class MyPhone extends Activity {
public final static String TAG = "MyPhone";
public final static String B_PHONE_STATE = TelephonyManager.ACTION_PHONE_STATE_CHANGED;
private MyPhoneBroadcastReceiver mBroadcastReceiver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_phone);
}
//按钮1-注册广播
public void registerThis(View v) {
Log.i(TAG, "registerThis");
mBroadcastReceiver = new MyPhoneBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(B_PHONE_STATE);
intentFilter.setPriority(Integer.MAX_VALUE);
registerReceiver(mBroadcastReceiver, intentFilter);
}
//按钮2-撤销广播
public void unregisterThis(View v) {
Log.i(TAG, "unregisterThis");
unregisterReceiver(mBroadcastReceiver);
}
}
第5步:在AndroidManifest.xml配置权限
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
其中:
iTelephony.answerRingingCall();//自动接通电话
必须有权限 android.permission.MODIFY_PHONE_STATE
iTelephony.endCall();//自动挂断电话
必须有权限 android.permission.CALL_PHONE。