當前位置:首頁 » 安卓系統 » togglebuttonandroid

togglebuttonandroid

發布時間: 2024-09-29 09:25:14

Ⅰ 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。

熱點內容
伺服器反查ip 發布:2024-09-29 11:18:18 瀏覽:17
連接oracle資料庫的工具 發布:2024-09-29 11:12:02 瀏覽:253
php系統變數 發布:2024-09-29 11:07:32 瀏覽:343
access資料庫是一個 發布:2024-09-29 11:06:59 瀏覽:509
exe反編譯工具下載 發布:2024-09-29 10:59:03 瀏覽:676
安卓手機開播如何設置 發布:2024-09-29 10:49:58 瀏覽:194
eclipse編譯產生的文件 發布:2024-09-29 10:49:20 瀏覽:931
配置cuda需要什麼顯卡 發布:2024-09-29 10:44:29 瀏覽:607
androidgridview載入 發布:2024-09-29 10:44:16 瀏覽:270
android用戶反饋 發布:2024-09-29 10:36:16 瀏覽:179