只需删除这个:
dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE);
编辑答案:
使用这种方式:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
viewList = getLayoutInflater().inflate(R.layout.activity_main_, null);
dialogMarketList = new Dialog(MainActivity.this);
dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogMarketList.setTitle("TOPICS");
dialogMarketList.setContentView(viewList);
dialogMarketList.show();
ListView lvForDialog = (ListView) viewList.findViewById(R.id.listView1);
header = inflater.inflate(R.layout.header, null);
lvForDialog.addHeaderView(header);
lvForDialog.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
ArrayAdapter<String> adapter = (new ArrayAdapter<String>(
MainActivity.this, android.R.layout.simple_list_item_1, a));
lvForDialog.setAdapter(adapter);
header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="my title"
android:textAppearance="?android:attr/textAppearanceLarge" />
第二次编辑:
滚动使用下面的代码时避免标题上升。
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("my Title");
builder.setIcon(getResources().getDrawable(R.drawable.ic_launcher));
builder.setAdapter(new ArrayAdapter<String>(MainActivity.this,
R.layout.row, R.id.child_row, items),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();