android - DialogWhenLarge 屏幕宽度太窄

标签 android android-layout

当设备是平板电脑时,我需要让我的对话 Activity ,比现在更宽并且使用更多的屏幕。

请看截图:

enter image description here

我需要它占屏幕宽度的 70% 左右吗?

有没有办法指定这个对话框的宽度。

为了实现这一点,我有以下内容:

样式.xml

<resources>

  <!-- Base application theme. -->
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
  </style>

  <style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>

  <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

  <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

  <style name="DialogTheme" parent="AppTheme"/>

</resources>

样式.xml (sw600dp)

<resources>
   <style name="DialogTheme" parent="Theme.AppCompat.DialogWhenLarge"/>
</resources>

list :

<manifest package="stillie.co.za.dialogwhenlarge"
          xmlns:android="http://schemas.android.com/apk/res/android">

  <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>
    <activity
        android:name=".DialogWhenLargeActivity"
        android:label="@string/title_activity_dialog_when_large"
        android:theme="@style/DialogTheme"> <-----------notice this-----------
    </activity>
  </application>
</manifest>

有谁知道只有在平板电脑上才能使屏幕宽度变宽。目前我是如何设置它的,当设备是手机时它工作正常,它应该是全屏的,但我遇到的唯一问题是当它是平板电脑时,对话框主题太窄了。

最佳答案

你有两个选择

  1. 创建自定义对话框并添加下行

    @Override
    public void onAttachedToWindow() {
        DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
        int width = metrics.widthPixels;
        int height = metrics.heightPixels;
        getWindow().setLayout(width * 70 / 100, height * 30 / 100);
        super.onAttachedToWindow();
    }
    

注意:根据您的要求更改百分比

或者

  1. 按照 IntelliJ Amiya 对当前对话的建议执行操作

关于android - DialogWhenLarge 屏幕宽度太窄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47049107/

相关文章:

android - 您必须传入一个非空 View

android - 什么时候应该停止服务

android - 您需要在 zendesk sdk 中将 Theme.AppCompat 主题(或后代)与此 Activity 一起使用

android - 如何在backpress时退出android应用程序?

android - 我想在安装时注册我的应用程序?

安卓 : Strike out Text with bold or thicker line than default STRIKE_THRU_TEXT_FLAG

android - Travis 无法构建 Android 项目,没有 local.properties

android - 如何使用 jsoup android 获取特定标签

java - 如何在选项卡菜单中使用抽屉导航

android - 在 Android layout_weight for Table Rows in dynamic Table