0

我有 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);
        }
    });
4

2 回答 2

1

setImageResource在调用之前使用,startActivityForResult并且startActivity作为:对于 GPS:

gpsimg.setImageResource(R.drawable.gps);
startActivity(myIntent);

对于蓝牙:

 bluetoothimg.setImageResource(R.drawable.bt);    
 startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT );
于 2012-05-25T05:53:54.727 回答
0

试试这个:

bluetoothimg.setBackgroundDrawable(getResources().getDrawable(
                    R.drawable.bt));
于 2012-05-25T05:47:37.180 回答