我有 3 个 GPS、WIFI、BLUETOOTH 的图像视图,如果 GPS、WIFI、BLUETOOTH 开启(以编程方式),我想更改每个图像视图的背景图像
如果 GPS、BLUETOOTH 开启,图像应该会改变,否则没有
我试过但它不工作
final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
gpsimg.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
//Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show();
//showGPSDisabledAlertToUser();
Intent myIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
gpsimg.setImageResource(R.drawable.gps);
}else if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
gpsimg.setImageResource(R.drawable.gps);
}
}
});
蓝牙代码在这里
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
if(!mBtAdapter.isEnabled())
{
bluetoothimg.setImageResource(R.drawable.bt_grey);
Log.i(TAG ,"BLUETOOTH DISABLED") ;
}
bluetoothimg.setOnClickListener(new View. OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
int REQUEST_ENABLE_BT = 1;
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT );
bluetoothimg.setImageResource(R.drawable.bt);
}
});