单击布局创建对话框
Create dialog on click over layout
我想要这样的东西:
当我点击我的自定义布局(由布局标题和一些其他布局内容组成 - 参见图片)时,它下方会出现一个小对话框,其中包含一些其他信息(由我的对话框和一些对话框信息组成 - 参见图片).
我在操作栏上放置了自定义布局。我只需要创建那个对话框并在那个地方显示它。
我的自定义操作栏布局 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/actionButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:gravity="end"
android:focusable="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:id="@+id/llInformation">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The layout title"
android:textSize="13dp"
android:id="@+id/tvLevel" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
... here comes some other layout things
</LinearLayout>
</RelativeLayout>
在我的主要 activity 代码中,我有:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
...//some other code
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
actionBar.setHomeAsUpIndicator(R.drawable.ic_drawer);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
LayoutInflater inflator = getLayoutInflater();
View v = inflator.inflate(R.layout.action_bar_layout, null);
LinearLayout informationLayout = (LinearLayout) v.findViewById(R.id.llInformation);
informationLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Code to call dialog
}
});
actionBar.setCustomView(v);
}
我唯一需要的是创建和显示该对话框的代码,如图所示。
谢谢:)
在布局文件中放置一个视图。根据需要将其更改为 "visible" 和 "gone"。
我想要这样的东西:
当我点击我的自定义布局(由布局标题和一些其他布局内容组成 - 参见图片)时,它下方会出现一个小对话框,其中包含一些其他信息(由我的对话框和一些对话框信息组成 - 参见图片).
我在操作栏上放置了自定义布局。我只需要创建那个对话框并在那个地方显示它。
我的自定义操作栏布局 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/actionButtonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:gravity="end"
android:focusable="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:id="@+id/llInformation">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The layout title"
android:textSize="13dp"
android:id="@+id/tvLevel" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
... here comes some other layout things
</LinearLayout>
</RelativeLayout>
在我的主要 activity 代码中,我有:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
...//some other code
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
actionBar.setHomeAsUpIndicator(R.drawable.ic_drawer);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
LayoutInflater inflator = getLayoutInflater();
View v = inflator.inflate(R.layout.action_bar_layout, null);
LinearLayout informationLayout = (LinearLayout) v.findViewById(R.id.llInformation);
informationLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Code to call dialog
}
});
actionBar.setCustomView(v);
}
我唯一需要的是创建和显示该对话框的代码,如图所示。
谢谢:)
在布局文件中放置一个视图。根据需要将其更改为 "visible" 和 "gone"。