다음 코드로 작업 표시 줄의 배경을 변경하려고 시도했습니다. 4.3 이하에서는 작동하지만 4.3 이하에서는 작동하지 않습니다. 다음 코드를 사용하면 널 배경이 설정됩니다. 즉. 오래된 배경이 제거되었지만 새 배경이 설정되지 않습니다. 도와주세요.작업 표시 줄 배경이 변경되지 않습니다.
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.testing);
}
/**
* Callback when button is clicked to change background
* @param v
*/
public void onStartClicked(View v) {
int Min = 0;
int Max = 2;
//Random number generator between 0 and 2 inclusive
int pos = Min + (int) (Math.random() * ((Max - Min) + 1));
if (pos == 0) {
getActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.header));
} else if (pos == 1) {
getActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.inbox_header));
} else if (pos == 2) {
getActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.outbox_header));
}
}
}
이 라인을 작성하십시오 - Drawable tmp = getResources(). getDrawable (R.drawable.outbox_header) 그리고 디버그하십시오. tmp는 null입니까? –
BitmapDrawable을 배경으로 사용하고 있습니까? – gunar
내 S3 (Android 4.1.2)에서 정상적으로 작동 중입니다. –