问题
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