小编Pav*_*hov的帖子

如何从DialogFragment中删除标题?

DialogFragment在我的项目中使用,我正在禁用标题

getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)

但我的对话变得歪曲了.我想保持对话框原样并删除标题.我能怎么做?

<?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:background="#ff2d35ff">


     <LinearLayout
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginRight="39dp"
         android:layout_marginLeft="39dp"
         android:layout_gravity="center_horizontal"
         android:background="#ff6cff23">

         <LinearLayout
             android:orientation="horizontal"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal">

             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="ItemName"
                 android:id="@+id/itemName"
                 android:layout_weight="1"
                 android:background="#ffd861ff"/>

             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="ItemPrice"
                 android:id="@+id/itemPrice"
                 android:layout_weight="1"
                 android:background="#ff2ff8ff"/>
     </LinearLayout>

     <ImageView
         android:layout_width="100dp"
         android:layout_height="100dp"
         android:id="@+id/itemImage"
         android:layout_gravity="center_horizontal"/>

     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="some test"
         android:id="@+id/textView9"
         android:layout_gravity="center_horizontal"/>

     <LinearLayout
         android:orientation="horizontal"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="center_horizontal"
         android:background="#ffffff2c">

         <Button
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="-"
             android:id="@+id/itemMinus"
             />

         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="1"
             android:id="@+id/textView11"
             android:layout_weight="1"
             android:gravity="center_horizontal"/>

         <Button
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="+"
             android:id="@+id/itemPlus"/>
     </LinearLayout>

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

android android-dialogfragment

7
推荐指数
2
解决办法
8326
查看次数

我该如何关闭片段?

我在活动上有片段.片段有按钮.如果我点击按钮,片段必须关闭.我是怎么做到的?

public class ItemFragment extends Fragment{

    private ImageView btnApply;
    private ClickButton clickButton = new ClickButton();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.item_info, container, false);
        btnApply = (ImageView) rootView.findViewById(R.id.btnSendItem);
        btnApply.setOnClickListener(clickButton);
        return rootView;
    }

    private class ClickButton implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            if (R.id.btnSendItem == v.getId()) {
                Toast.makeText(getActivity(),"CLOSE",Toast.LENGTH_LONG).show();
                return;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

android android-fragments

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