使用setStyle时,DialogFragment中的Android ListView存在错误
我在使用带有ListView的DialogFragment时遇到问题。当我在onCreate中使用setStyle时,问题就出现了 以下是代码(为了更清楚地说明问题,我将列表文本视图涂成了洋红色): 下面是它提供的对话框的图像: 现在,如果我只是注释setStyle(STYLE_NO_TITLE,0);行在onCreate方法中,一切按预期工作: 我做错了什么? 我不能使用简单的AlertDialog,因为我需要自定义更多的列表项 编辑:使用setStyle时,DialogFragment中的Android ListView存在错误,android,android-ui,android-4.0-ice-cream-sandwich,android-dialog,android-dialogfragment,Android,Android Ui,Android 4.0 Ice Cream Sandwich,Android Dialog,Android Dialogfragment,我在使用带有ListView的DialogFragment时遇到问题。当我在onCreate中使用setStyle时,问题就出现了 以下是代码(为了更清楚地说明问题,我将列表文本视图涂成了洋红色): 下面是它提供的对话框的图像: 现在,如果我只是注释setStyle(STYLE_NO_TITLE,0);行在onCreate方法中,一切按预期工作: 我做错了什么? 我不能使用简单的AlertDialog,因为我需要自定义更多的列表项 编辑: list.xml <?xml version=
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
在你的
文本视图上使用android:minWidth=“360dp”
这个问题让我今天一整天都发疯,它肯定是系统中的一个bug。我最终做的是,我留下了样式没有标题,因为我真的不想处理标题,我的其他对话框样式都是主题:
fragment.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog);
这当然会给一些手机带来问题,这不仅仅是背景问题,也是一个可触及的领域。现在,我的项目xml布局中出现了令人讨厌的黑客补丁:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:height="48dp"
android:width="600dp"
android:textSize="19sp"
android:textColor="@color/blue"
android:paddingLeft="16dp"
android:gravity="center_vertical"
/>
将宽度硬编码为大值是一个技巧,但我不太确定它如何影响低分辨率设备的性能。在KindleFire、Nexus7和2.2版本的模拟器上测试
希望这将有助于某人在onCreate方法中使用此代码
getDialog().getWindow().requestFeature(Window.FEATURE\u NO\u TITLE)代码>问题是您设置了文本视图的背景和颜色而不是行。这并不能解决问题。我已经用一个演示项目创建了一个存档。我已经在galaxy tab(android 3.2)和galaxy s(android 4.0.4)上运行了您的演示项目。两种风格都很好。(在这两种情况下,行都是粉红色的)。我只测试了果冻豆。。。我猜这是一个平台错误。嗨,Salomon BRYS问题已经解决。检查编辑应答测试后,请告知它是否正确?geDialog()在onCreate()内返回null,您得到一个java.lang.NullPointerExceptiontrygetActivity().getDialog().getWindow().requestFeature(Window.FEATURE\u NO\u TITLE)代码>
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list, container);
ListView v=(ListView) view.findViewById(R.id.list);
v.setAdapter(new BaseAdapter() {
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = null;
if (convertView == null) {
rowView = inflater.inflate(R.layout.menu_rowview, parent, false);
}
else
rowView = convertView;
LinearLayout lay=(LinearLayout) rowView.findViewById(R.id.linear);
lay.setBackgroundColor(Color.MAGENTA);
TextView textView = (TextView) rowView.findViewById(R.id.textView1);
switch (position) {
case 0: textView.setText("Random"); break;
case 1: textView.setText("Community favourites"); break;
case 2: textView.setText("Change image"); break;
case 3: textView.setText("Share"); break;
case 4: textView.setText("Informations"); break;
}
return rowView;
}
@Override public long getItemId(int arg0) {
return arg0; }
@Override public Object getItem(int arg0) { return arg0; }
@Override public int getCount() { return 5; }
});
return view;
}
fragment.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog);
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:height="48dp"
android:width="600dp"
android:textSize="19sp"
android:textColor="@color/blue"
android:paddingLeft="16dp"
android:gravity="center_vertical"
/>