相关疑难解决方法(0)

如何在android中创建自定义对话框?

我想创建一个自定义对话框,如下所示

在此输入图像描述

我尝试过以下的事情.

  1. 我创建了AlertDialog.Builder的子类,并使用了自定义标题和自定义内容视图并使用了它,但结果并不像预期的那样.

  2. 另一种尝试是继承DialogFragment并在onCreateDialog中自定义对话框,但结果不是预期的.

  3. 然后我尝试使用普通的Dialog类.结果并不像预期的那样.

在所有三种情况下,问题是当我忽略标题视图时,对话框的大小不是预期的,当我使用标题视图时,结果是内容视图周围有一个粗边框(实际上看起来很糟糕).现在我脑子里有两个问题......

  1. 我怎样才能做到这一点?由于我已经尝试了很多东西,因此我们将更加赞赏直接的答案.

  2. 在Android应用程序中显示错误或警告对话框的最佳方法是什么?

编辑 Android开发人员文档建议我们应该使用DialogFragments或Dialogs向用户显示错误/警报消息.但有一次他们说......

提示:如果需要自定义对话框,则可以将"活动"显示为对话框,而不是使用"对话框API".只需创建一个活动,并将其主题设置为清单元素中的Theme.Holo.Dialog.

那是什么意思?使用Activity只是为了显示错误消息是不是太多了?

android android-dialog android-dialogfragment

333
推荐指数
10
解决办法
56万
查看次数

如何在Android中创建弹出窗口(PopupWindow)

要创建一个简单的工作PopupWindow,我们需要执行以下操作:

popup_example.xml:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:padding="10dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView         
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:text="Test Pop-Up" />

    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Java代码

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100,100, true);

pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);
Run Code Online (Sandbox Code Playgroud)

我的要求是我需要一个

<TEXTVIEW android:layout_height="wrap_content" android:layout_width="fill_parent" />
Run Code Online (Sandbox Code Playgroud)

和a

<BUTTON android:id="@+id/end_data_send_button" android:text="Cancel"/>
Run Code Online (Sandbox Code Playgroud)

在我的popup_example.xml.如何在Java代码中处理这两个组件?

截图

android popupwindow android-popupwindow

45
推荐指数
5
解决办法
17万
查看次数

重力值如何影响Android中的PopupWindow.showAtLocation()

不同的Gravity值如何影响Android中的PopupWindow.showAtLocation()?

我在PopupWindows showAtLocation和Gravity上找不到好的文档.

android

37
推荐指数
2
解决办法
3万
查看次数

如何制作横向ContextMenu?

我已经打了一个Activity电话Accounts,我想添加一个横向ContextMenu.这可能看起来像剪切,复制和粘贴选项.有没有办法onLongClick在列表项上添加这个水平自定义菜单?

这是我到目前为止所得到的.

@Override      
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    LayoutInflater inflater = getLayoutInflater().from(this);
    View view = inflater.inflate(R.layout.custom_listview, null, false);
    menu.setHeaderView(view);
    menu.add("Delete");
    menu.add("Edit");
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int position = info.position;
    View v = listView.getChildAt(position);
    TextView typeTv = v.findViewById(R.id.custom_listview_type);
    TextView userTv = v.findViewById(R.id.custom_listview_user);
    TextView passTv = v.findViewById(R.id.custom_listview_password);

    if (item.getTitle().equals("Delete")) {
        db.execSQL("delete from user_added_accounts where accountType = '" + typeTv.getText().toString() …
Run Code Online (Sandbox Code Playgroud)

java android contextmenu

9
推荐指数
1
解决办法
1342
查看次数