简体   繁体   中英

Android UI in C++

I know this is kind of reinventing the wheel, but how hard would it be to implement an android user interface with C++? Is it hard to create things like buttons, and to handle touch screen events like button clicks? Is this feasible and if so, how would you go about doing it?

Take a look at Necessitas , its a Qt port for android which seems to work pretty well.

It might still be in Alpha or Beta stage though, so it will depends on how "serious" your project is. But that proves for sure that one can use plain C++ to build a complete application, not only libraries.

You can use JNIpp to create wrapper for activity and all UI classes you are interested in. Take a look at HelloJNIpp sample , it features native Activity, native custom drawn View and a button.

Spoiler:

void MainActivity::OnCreate(const jni::LObject& bundle) {
    Activity::OnCreate(bundle);
    SetContentView(R::GetLayout("main"));
    FindViewById(R::GetID("changeColor"))->
        SetOnClickListener(*this,&MainActivity::ChangeColor);
}

You can always use the JNI to go back up into java to get UI components on the screen. If you set it up to be little more than an API, you can simulate actually doing it in native code. NVidea has some good samples on how to do this: http://developer.nvidia.com/tegra-resources This library code isn't doing it for UI components, but is for various other things (sound, resources, etc). and the idea should work for UI components too.

Also, this project supposedly supports the entire sdk in c++, and I would imagine it's doing it the same way. I don't know how up to date it is, as I haven't actually used it: http://code.google.com/p/android-cpp-sdk/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM