簡體   English   中英

Android 5上的活動對話框小而空

[英]Activity dialog small and empty on Android 5

我有活動

public class DeviceListActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_devices_list);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }
}

並在清單中:

<activity android:name="com.myapp.DeviceListActivity"
        android:screenOrientation="landscape" 
        android:theme="@style/Theme.AppCompat.Light.Dialog" />

要打開它:

Intent intent = new Intent(this,
            BluetoothDeviceListActivity.class)
startActivity(intent)

在我的Samsung Galaxy Tab A Android 7.0上,它可以完美運行,該活動作為對話框打開,我可以看到其中的內容。

在三星平板電腦上工作

但是我正在運行Android 5.2的仿真器(WSVGA_7)上進行嘗試,對話框很小,空白為空。

不適用於5.2

如何使Dialog活動在所有android版本中均顯示為相同,而不顯示為空白? 我也嘗試使用Activity而不是AppCompatActivity,但存在相同的問題。

謝謝

編輯:

這是活動的布局文件:activity_devices_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

    <Button
        android:id="@+id/scan_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/transparent"
        android:textSize="@dimen/unit_16_text"
        android:textColor="@color/green"
        android:text="@string/scan"
        android:layout_alignParentEnd="true"
        android:gravity="center"
        android:textAlignment="center" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:max="100"
        android:backgroundTint="@color/white"
        android:indeterminateTint="@color/colorAccent"
        android:visibility="invisible"
        android:layout_below="@id/scan_button"/>

    <ListView android:id="@+id/listViewDevices"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/progressBar"
        />

    <TextView
        android:id="@+id/title_label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/progressBar"
        android:layout_alignTop="@id/scan_button"
        android:layout_alignParentStart="true"
        android:layout_marginStart="0dp"
        android:layout_toStartOf="@id/scan_button"
        android:gravity="center_vertical"
        android:paddingLeft="8dp"
        android:text="@string/settings_printers_connection_settings"
        android:textColor="@color/green"
        android:textSize="18dp"
        android:textStyle="bold" />




</RelativeLayout>

嘗試使用getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 在您活動的onCreate方法中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM