相关疑难解决方法(0)

如何在android中制作渐变背景

我想创建渐变背景,其中渐变位于上半部分,下半部分是纯色,如下图所示:

我不能因为centerColor展开以覆盖底部和顶部.

在按钮的渐变中,白色水平线在顶部和底部逐渐变为蓝色.

如何制作像第一张图像的背景?如何制作centerColor不散布的小号?

这是上面背景按钮的XML代码.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient 
        android:startColor="#6586F0"
        android:centerColor="#D6D6D6"
        android:endColor="#4B6CD6"
        android:angle="90"/>
    <corners 
        android:radius="0dp"/>


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

android gradient background shapes

201
推荐指数
8
解决办法
37万
查看次数

如何实现自定义AlertDialog视图

AlertDialog上Android文档中,它提供了以下用于在AlertDialog中设置自定义视图的说明和示例:

如果要显示更复杂的视图,请查找名为"body"的FrameLayout并将视图添加到其中:

FrameLayout fl = (FrameLayout) findViewById(R.id.body);
fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud)

首先,非常明显的是这add()是一个错字,并且意味着addView().

我对使用R.id.body的第一行感到困惑.它似乎是AlertDialog的body元素......但是我不能在我的代码中输入它b/c它会产生编译错误.R.id.body在哪里被定义或分配或者其他什么?

这是我的代码.我试图setView(findViewById(R.layout.whatever)在构建器上使用但它没有用.我假设因为我没有手动充气吗?

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title")
    .setCancelable(false)
    .setPositiveButton("Go", new DialogInterface.OnClickListener() {

    @Override
    public void onClick(DialogInterface dialog, int id) {
        EditText textBox = (EditText) findViewById(R.id.textbox);
        doStuff();
    }
});

FrameLayout f1 = (FrameLayout)findViewById(R.id.body /*CURRENTLY an ERROR*/);
f1.addView(findViewById(R.layout.dialog_view));

AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog

105
推荐指数
6
解决办法
21万
查看次数

如何在android中制作带圆角的自定义对话框

我想做的是:我正在尝试制作自定义对话框.圆角.

什么是happing:我能够进行自定义对话,但它没有圆角.我尝试添加一个选择器,但我还是不能


Java代码:

private void launchDismissDlg() {

        dialog = new Dialog(getActivity(), android.R.style.Theme_Dialog);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dlg_dismiss);
        dialog.setCanceledOnTouchOutside(true);

        Button btnReopenId = (Button) dialog.findViewById(R.id.btnReopenId);
        Button btnCancelId = (Button) dialog.findViewById(R.id.btnCancelId);

        btnReopenId.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {



            }
        });


        btnCancelId.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {



            }
        });
        dialog.setCanceledOnTouchOutside(false);
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
        dialog.show();

    }
Run Code Online (Sandbox Code Playgroud)

xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:gravity="center" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-dialog

94
推荐指数
14
解决办法
10万
查看次数