之前代码如下:
public class PlayerActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_player);
}
}
运行后提示: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.down.musicdemo/
com.example.down.musicdemo.PlayerActivity}: android.util.AndroidRuntimeException: requestFeature() musts be called before adding content
最终发现继承的是ActionBarActivity 而不是 Activity;
class PlayerActivity extends ActionBarActivity {}
所以这个时候的写法应该是:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();