save code
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package com.khronos.vulkan_samples;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Debug;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
@@ -17,8 +21,8 @@ public class MainActivity extends GameActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
String native_lib_name = getResources().getString(R.string.native_lib_name);
|
||||
try {
|
||||
String native_lib_name = getResources().getString(R.string.native_lib_name);
|
||||
System.loadLibrary(native_lib_name);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
Toast.makeText(getApplicationContext(), "Native code library failed to load.", Toast.LENGTH_SHORT).show();
|
||||
@@ -29,6 +33,47 @@ public class MainActivity extends GameActivity {
|
||||
sendArgumentsToPlatform(argArray);
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.i("MainActivity", "onCreate: ");
|
||||
|
||||
// 添加按钮到布局
|
||||
addButtonToLayout();
|
||||
}
|
||||
|
||||
private void addButtonToLayout() {
|
||||
// 创建按钮
|
||||
Button button = new Button(this);
|
||||
button.setText("Vulkan 按钮");
|
||||
|
||||
// 设置按钮位置(使用绝对坐标)
|
||||
button.setX(50); // 距离左边50像素
|
||||
button.setY(50); // 距离顶部50像素
|
||||
|
||||
// 设置按钮点击事件
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onButtonClicked();
|
||||
}
|
||||
});
|
||||
|
||||
// 将按钮添加到 GameActivity 的布局中(不会覆盖 Vulkan 表面)
|
||||
addContentView(button, new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
private void onButtonClicked() {
|
||||
Toast.makeText(this, "Vulkan 按钮被点击了!", Toast.LENGTH_SHORT).show();
|
||||
nativeButtonClicked();
|
||||
// 启动SecondActivity
|
||||
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
|
||||
// 可以传递数据
|
||||
intent.putExtra("message", "Hello from MainActivity!");
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private native void nativeButtonClicked();
|
||||
|
||||
private native void sendArgumentsToPlatform(String[] args);
|
||||
}
|
||||
Reference in New Issue
Block a user