【问题标题】:ActionBar is appearing in the first activity but not appearing the second oneActionBar 出现在第一个活动中,但没有出现在第二个活动中
【发布时间】:2015-07-18 15:09:20
【问题描述】:

我有一个包含三个活动的应用程序,主题设置为 Light.DarActionBar,第一个活动有操作栏,而第二个没有。如何让它出现在第二个活动中?

我的类 Profile.java

public class Profile extends Activity { 
    private Button modeBtn;
    private Button increaseBtn;
    private Button decreaseBtn;
    ...
    ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_profile);
        ...
        ...
    }

    ...
    ...

    public void silentEnable(View view){
        // set the ring mode to silent
        myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        status.setText("Current Status: Silent Mode");
    } 
}

【问题讨论】:

标签: java android eclipse android-studio


【解决方案1】:

刚刚换了这个

public class Profile extends Activity

有了这个

public class Profile extends ActionBarActivity

【讨论】:

  • 这不是有效的答案。你觉得Activity没有action bar吗?
【解决方案2】:

您应该扩展 AppCompatActivity。你仍然可以使用 getSupportActionBar().show()

ActionBarActivity 为 deprecated,更新为 22.1.0

【讨论】:

    【解决方案3】:

    如果你的activity扩展了ActionBarActivity,那么添加

    getSupportActionBar().show();
    

    如果你的activity扩展了Activity,那么添加

    getActionBar().show();
    

    为应用程序而不是活动设置主题(具有操作栏)。

    【讨论】:

    • 我应该在哪里添加这个??在 OnCreate 方法下
    • 显然你必须在 OnCreate 方法中添加这个
    【解决方案4】:

    我想,你已经在清单文件的活动标签中定义了你的应用程序主题。在应用程序标签中定义你的应用程序主题。

    希望对您有所帮助。但是,如果您有任何困惑,请上传您的清单文件,以便我查看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-10
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多