Android ActionBar missing after extending Appcompatactivity

筅森魡賤 提交于 2019-12-11 19:04:49

问题


I've recently updated my app extending Appcompatactivity in my Activities. Since then, the Actionbar is gone when I launch an external library Intent.

For example, I'm using the HockeyApp SDK to launch their FeedbackActivity

Here is my code:

FeedbackManager.showFeedbackActivity(this, Uri.fromFile(file));

And here a screenshot (you can see the ActionBar is gone).

It used to work before until I started extending Appcompatactivity.

For the rest of Activities it works. The ActionBar is gone only when I launch an external library Intent.

Any ideas?


回答1:


First, check your theme it may be like below ("NoActionBar"). Then the action bar is not appearing. If this is your issue. please add an appropriate theme for your application

 <application
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    />

if your theme is not a problem, you can add below content to your XML file. (add this as a first child of your XML file)

<android.support.v7.widget.Toolbar
   android:id="@+id/my_toolbar"
   android:layout_width="match_parent"
   android:layout_height="?attr/actionBarSize"
   android:background="?attr/colorPrimary"
   android:elevation="4dp"
   android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
   app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

and add below content to your activity on create method

protected void onCreate(Bundle savedInstanceState) {
    .......
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);
}



回答2:


The reason is probably that FeedbackManager.showFeedbackActivity(this, Uri.fromFile(file)) opens a new FeedbackActivity.class which is subclass of Activity.class instead of AppCompatActivity.class, so it can not show the ActionBar.Here is a link https://stackoverflow.com/questions/30681918/nullpointerexception-with-actionbar-setdisplayhomeasupenabledboolean-on-a-nu that explains some reasons.



来源:https://stackoverflow.com/questions/53086154/android-actionbar-missing-after-extending-appcompatactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!