正如多个answers中所述,调用requestWindowFeature(Window.FEATURE_NO_TITLE)
应该在super.onCreate(...)
和setContentView(...)
之前。
但是,我希望在创建活动时显示屏幕标题,并且只有在 从其他活动返回后才会消失。
我试过这个:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CONNECT_DEVICE:
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
}
我收到android.util.AndroidRuntimeException: requestFeature() must be called before adding content
例外。
答案 0 :(得分:1)
// try this way,hope this will help you....
Note : i think what you trying do is not possible so try this alternative.
public class FirstActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if(!getIntent().getBooleanExtra("isTitleShow",true)){
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// this condition for stop to call SecondActivity after one time call
if(getIntent().getBooleanExtra("isTitleShow",true)){
Intent intent = new Intent(this,SecondActivity.class);
startActivity(intent);
finish();
}
}
}
public class SecondActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this,MainActivity.class);
intent.putExtra("isTitleShow",false);
startActivity(intent);
}
}