首先是类
package com.hao;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.TextView;
import com.example.kamisama.lbstest.R;
public class BottomStyleDialog extends Dialog {
private Button poisearch;
private Button routesearch;
private Button look;
private TextView title;
private TextView detail;
private String Title;
private String Detail;
public BottomStyleDialog(Context context,String Title,String Detail) {
// 在构造方法里, 传入主题
super(context, R.style.BottomDialogStyle);
// 拿到Dialog的Window, 修改Window的属性
Window window = getWindow();
window.getDecorView().setPadding(0, 0, 0, 0);
// 获取Window的LayoutParams
LayoutParams attributes = window.getAttributes();
attributes.width = LayoutParams.MATCH_PARENT;
attributes.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
// 一定要重新设置, 才能生效
window.setAttributes(attributes);
this.Title=Title;
this.Detail=Detail;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_view);
setTitle(Title,Detail);
initView();
}
private void initView() {
routesearch=(Button)findViewById(R.id.routesearch);
poisearch=(Button)findViewById(R.id.poisearch);
look=(Button)findViewById(R.id.look);
title=(TextView)findViewById(R.id.title);
detail=(TextView) findViewById(R.id.detail);
look.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
}
});
routesearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
poisearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
private void setTitle(String Title,String Detail)
{
title.setText(Title);
detail.setText(Detail);
}
}
然后是layout页面的dialog_view.xml,也就是dialog的填充界面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Title"
android:textColor="#000000"
android:textSize="30sp"/>
<TextView
android:id="@+id/detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#000000"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:gravity="bottom|center_horizontal"
android:paddingBottom="10dp">
<Button
android:id="@+id/look"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="查看评论"/>
<Button
android:id="@+id/poisearch"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="搜周边"/>
<Button
android:id="@+id/routesearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="导航"/>
</LinearLayout>
</LinearLayout>
最后是显示:
BottomStyleDialog bottomStyleDialog=new BottomStyleDialog(Main2Activity.this,"hah","nihao");
bottomStyleDialog.show();