1. 程式人生 > >01_c++下jni開發說明

01_c++下jni開發說明

img margin ati 函數 end create ica activit jni

技術分享

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="helloincpp" android:text
="調用C++函數" /> </RelativeLayout>
package com.itheima.cppjni;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void helloincpp(View v){ Toast.makeText(this, hellocpp(), Toast.LENGTH_SHORT).show(); } public native String hellocpp(); }

Java的代碼咱們就寫好了.接下來是寫C++的代碼.


技術分享

Android Tools->Add Native Support

技術分享

技術分享

技術分享

01_c++下jni開發說明