DialogWhenLarge屏幕宽度太窄 [英] DialogWhenLarge screen width too narrow

查看:82
本文介绍了DialogWhenLarge屏幕宽度太窄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当设备是平板电脑时,我需要进行对话活动,并且比当前设备更宽且使用更多的屏幕.

I need to make my dialog activity when the device is a tablet, wider and use more of the screen than it currently is.

请查看屏幕截图:

我需要它大约是屏幕宽度的70%吗?

I need it to be about 70% of the screen width?

有没有一种方法可以指定此对话框的宽度.

Is there a way to specify the width of this dialog.

要实现这一点,我需要执行以下操作:

To achieve this I have the following:

styles.xml

styles.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>

styles.xml(sw600dp)

styles.xml (sw600dp)

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

清单:

<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>

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

Does anyone know how to make the screen width wider only when its on a tablet. How I have it set up at the moment, it works fine when the device is a phone its full screen like it should be but the only issue I have is when its a tablet, the dialog theme is too narrow.

推荐答案

您有两个选择

  1. 创建自定义对话框&在第

  1. Create custom dialog & add below line

@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();
}

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

Note: Change percentage as per your requirement

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

这篇关于DialogWhenLarge屏幕宽度太窄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆