当设备是平板电脑时,我需要让我的对话 Activity ,比现在更宽并且使用更多的屏幕。
请看截图:
我需要它占屏幕宽度的 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>
有谁知道只有在平板电脑上才能使屏幕宽度变宽。目前我是如何设置它的,当设备是手机时它工作正常,它应该是全屏的,但我遇到的唯一问题是当它是平板电脑时,对话框主题太窄了。
最佳答案
你有两个选择
创建自定义对话框并添加下行
@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(); }
注意:根据您的要求更改百分比
或者
- 按照 IntelliJ Amiya 对当前对话的建议执行操作
关于android - DialogWhenLarge 屏幕宽度太窄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47049107/