我有自己的 constants.xml
文件,如下所示 -
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="dialog_fragment_height">7</integer>
<integer name="dialog_fragment_width">8</integer>
</resources>
现在我需要在 Java 文件中读取这个值并将其用作窗口参数 -
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int)(width * //read here width ),(int)(height * //read here height));
我该怎么做?
最佳答案
您可以使用以下代码提取它:
int width = getContext().getResources().getInteger(R.integer.dialog_fragment_height);
关于java - Android从常量xml读取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39039880/