How to use the app bar with NativeActivity?

113 views
Skip to first unread message

Andreas Falkenhahn

unread,
Mar 27, 2018, 10:04:39 AM3/27/18
to andro...@googlegroups.com
Is it possible to have an app bar on top of a NativeActivity whose contents are drawn by C code writing raw pixels into the memory buffer obtained from ANativeWindow_lock()?

I've read the App Bar developer tutorial provided by Google at https://developer.android.com/training/appbar/setting-up.html but it says that activities using the App Bar should extend AppCompatActivity, i.e.

public class MyActivity extends AppCompatActivity { }

and then call setSupportActionBar(). But how can I make this work with NativeActivity? I don't know much about Java but I don't think it's possible to write an activity which extends two activities, i.e. AppCompatActivity *and* NativeActivity, is it?

So is it possible to use the App Bar together with a NativeActivity at all?

--
Best regards,
Andreas Falkenhahn mailto:and...@falkenhahn.com

Philippe Simons

unread,
Mar 27, 2018, 10:24:26 AM3/27/18
to android-ndk
it's possible since NativeActivity extends framework Activity, you have access to the native ActionBar.
So you should be able to setup a menu to it.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/1485448003.20180327160429%40falkenhahn.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Falkenhahn

unread,
Mar 27, 2018, 11:36:25 AM3/27/18
to Philippe Simons
On 27.03.2018 at 16:23 Philippe Simons wrote:

> it's possible since NativeActivity extends framework Activity, you
> have access to the native ActionBar.
> So you should be able to setup a menu to it.

Thanks. Unfortunately, the Action Bar is probably not fit for my
needs. I'll post a follow-up question...

Andreas Falkenhahn

unread,
Mar 27, 2018, 2:53:06 PM3/27/18
to Philippe Simons
On 27.03.2018 at 16:23 Philippe Simons wrote:

> it's possible since NativeActivity extends framework Activity, you
> have access to the native ActionBar.
> So you should be able to setup a menu to it.

Hmm, are you sure that this is possible? I'm having a really hard time
trying to get an ActionBar on top of my NativeActivity. It's very hard
to find sample code because obviously everybody uses the AppCompat-style
bars which I cannot use because of NativeActivity.

So I've tried the following instead:

public class MyActivity extends android.app.NativeActivity {

@Override
public void onCreate(Bundle savedInstanceState) {

this.requestWindowFeature(Window.FEATURE_ACTION_BAR);

super.onCreate(savedInstanceState);

getActionBar().show();
}
}

But it doesn't work. No ActionBar is shown. Any ideas?

Philippe Simons

unread,
Mar 27, 2018, 2:58:42 PM3/27/18
to android-ndk
could you try using the Theme

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Andreas Falkenhahn

unread,
Mar 27, 2018, 3:11:03 PM3/27/18
to Philippe Simons
On 27.03.2018 at 20:58 Philippe Simons wrote:

> could you try using the Theme

I've tried the following:

In res/values/styles.xml:

<resources>
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>

In AndroidManifest.xml:

<activity android:name=".MyActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:theme="@style/CustomActionBarTheme">

But it still doesn't work. It doesn't show an ActionBar :-(

Philippe Simons

unread,
Mar 27, 2018, 3:18:54 PM3/27/18
to android-ndk
if you don't apply any theme, you should still see the window title? no ?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

Andreas Falkenhahn

unread,
Mar 27, 2018, 3:30:46 PM3/27/18
to Philippe Simons
On 27.03.2018 at 21:18 Philippe Simons wrote:

> if you don't apply any theme, you should still see the window title? no ?

No, there is no window title when not setting a theme...
Reply all
Reply to author
Forward
0 new messages