android - Android 弹出对话框屏幕大小在 android Oreo 中没有变化
问题描述
我正在做安卓项目。我想在我的活动中显示一个弹出对话框。我已经实现了它(下面附上的所有代码)。但我的问题是,当我在 android 中运行这个项目时,弹出窗口显示如下。我需要增加这个弹出对话框的宽度。我尝试了一些解决方案,但对我不起作用。请帮我解决这个问题。提前致谢。
这是我的代码
xml文件——
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lv_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="MSGP3006"
android:textColor="@color/Black"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QTY:2 | Weight : 500g | Discount::25%"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_marginBottom="@dimen/dimen_5dp"
android:layout_gravity="bottom">
<TextView
android:id="@+id/amount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Rs.360.00"
android:gravity="end"
android:textColor="@color/Sky_Dark_Blue"
android:textSize="22sp"/>
</LinearLayout>
</LinearLayout>
java文件——
public class AddInvoiceDialog extends Dialog {
public Activity activity;
public Dialog dialog;
public Button btn_add;
public AddInvoiceDialog(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.activity = a;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.inv_add_new_invoice_popup);
btn_add = (Button) findViewById(R.id.btn_add);
btn_add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
activity.finish();
}
});
}
}
解决方案
在后面添加以下行setContentView(R.layout.inv_add_new_invoice_popup);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
您将获得与设备宽度匹配的弹出窗口。
您还需要添加android:orientation="vertical"
您的 parent LinearLayout
,它包含多个孩子。
推荐阅读
- php - 基于从选项字段中选择的选项从数据库表列中获取变量到输入字段
- android - 模拟器不断重启Android Studio 3.1.4?
- multithreading - 一个进程如何使用套接字处理 Web 服务器上的多个请求?TCP
- javascript - 如何使用节点 js 生成 cookie?
- google-cloud-platform - 谷歌云永久磁盘中的根永久磁盘和非根永久磁盘
- sql - SQL:在特定天数后更新列
- angular - 每条记录多行的角度材料表
- docker - Docker:无法从 Spring Boot 应用程序读取类路径资源
- python - 添加
列表前的标签 - openssl - phpseclib 仅使用公钥解密和加密数据