gpt4 book ai didi

java - 如何使用 okay 按钮关闭 android 弹出窗口

转载 作者:行者123 更新时间:2023-11-30 01:31:21 27 4
gpt4 key购买 nike

我正在为一个学校项目制作一个应用程序,但我被困在一个领域。我想使用一个确定按钮关闭弹出窗口。如果您有任何建议或有更好的弹出窗口实现方式,请分享。

package xyz.ashraf.whoisdelasalle;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;

public class Pop extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.popwindow);

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);

int width = dm.widthPixels;
int height = dm.heightPixels;

getWindow().setLayout((int)(width*.8),(int)(height*.5));

}
}

Java代码^

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#FAFAFA">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="John Baptist de La Salle was a French priest, educational reformer, and founder of the Institute of the Brothers of the Christian Schools. He is a saint of the Roman Catholic Church and the patron saint of teachers."
android:id="@+id/textView"
android:background="#FAFAFA"
android:textColor="#000000"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:id="@+id/okButton_who"
android:textColor="#00E676"
android:background="#FAFAFA"
android:layout_below="@+id/textView"
android:layout_alignRight="@+id/textView"
android:layout_alignEnd="@+id/textView"
android:layout_marginTop="50dp"/>

</RelativeLayout>
</ScrollView>

XML^

提前致谢!

最佳答案

不确定这是否可行,但您可以尝试:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.popwindow);

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);

int width = dm.widthPixels;
int height = dm.heightPixels;

getWindow().setLayout((int)(width*.8),(int)(height*.5));

Button okButton = (Button) findViewById(R.id.okButton_who);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

}

否则您可以按照 akadouri 的建议使用 Dialogs 或 DialogFragments。

关于java - 如何使用 okay 按钮关闭 android 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35717102/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com