从膨胀的布局中删除黑色边框

Bud*_*ddy 6 android android-layout

我正在使用PopupWindow,效果很好,但是问题是在放大显示有黑色边框的布局视图之后。

final PopupWindow popupWindow = new PopupWindow(context);
LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pop_up_window_menu_layout, null);
popupWindow.setContentView(view);
Run Code Online (Sandbox Code Playgroud)

pop_up_window_menu_layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/solid_white"
android:orientation="vertical" >

<TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:text="SAVE"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textColor="@color/black"
        android:textSize="@dimen/txt_size_sliding_list" />
Run Code Online (Sandbox Code Playgroud)

我尝试使用删除边框popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)),但问题仍然相同。

谁能告诉我如何删除不需要的黑色边框?

mpk*_*uth 5

我的弹出窗口周围没有看到任何边框,但我将其设置为与您稍有不同。希望这为您指明了正确的方向。

popup_view.xml

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

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <Button
        android:id="@+id/btn_close"
        android:text="Close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

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

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:id="@+id/main_view"
                tools:context=".MainActivity">

    <Button
        android:id="@+id/btn_popup"
        android:text="Popup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/txt_text"
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

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

MainActivity.java

public class MainActivity extends ActionBarActivity implements View.OnClickListener {

    View popupView;
    Button btnPopup;
    Button btnClose;
    PopupWindow popupWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
        btnClose = (Button) popupView.findViewById(R.id.btn_close);
        btnClose.setOnClickListener(this);

        popupWindow = new PopupWindow(popupView,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);

        btnPopup = (Button) findViewById(R.id.btn_popup);
        btnPopup.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_popup) {
            popupWindow.showAtLocation(findViewById(R.id.main_view), Gravity.NO_GRAVITY, 100, 200);
            //popupWindow.showAsDropDown(btnPopup, 10, 10);
        } else if (v.getId() == R.id.btn_close) {
            popupWindow.dismiss();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

屏幕截图


Par*_*ria 5

如果出现黑色边框,则表示已设置默认背景。

这是删除它的方法:

popup.setBackgroundDrawable(null);
Run Code Online (Sandbox Code Playgroud)

尝试这个