2016-12-26 156 views
-1

我想让我的alert dialog box类似this.This是,你必须选择和选择category.Its来临,当我点击任何listview项目的弹出窗口我的警告对话框..怎样才能让android中

enter image description here

但我最终做出了这样的事情,因为我是一个新手,所以对设计知之甚少,在此帮助我。

enter image description here

我的XML布局:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:background="#FFFFFF" 
    android:gravity="start" 
    android:orientation="vertical"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 



     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 

      android:layout_weight="1" 
      android:orientation="vertical" > 

      <ImageView 
       android:id="@+id/desimage" 
       android:layout_weight="1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="2dp" 
       android:layout_marginTop="10dp" 
       android:src="@drawable/logo" /> 

     </LinearLayout> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="5dp" 
      android:layout_weight="1" > 

      <TextView 
       android:text="Chicken Pizza Small" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="21sp" 
       android:textStyle="bold" 
       android:id="@+id/h1" 
       android:layout_weight="1" /> 


     </LinearLayout> 

     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_weight="1" > 
     <TextView 
      android:text="Chicken Pizza Small Combo" 
      android:layout_width="wrap_content" 
      android:textSize="16sp" 
      android:layout_height="wrap_content" 
      android:textColor="#8c8181" 
      android:id="@+id/h2" 
      android:layout_weight="1" /> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_weight="1" > 

     <Button 
      android:text="Quantity" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/mybutton" 
      android:textColor="#ffffff" 
      android:id="@+id/quant" 
      android:layout_weight="1" /> 


     <Button 
      android:text="-" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/incr" 
      android:textSize="10sp" 
      android:textColor="@color/colorButton" 
      android:layout_weight="1" /> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="number" 

      android:layout_weight="1" 
      android:id="@+id/n1" 
      /> 

     <Button 
      android:text="+" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="10sp" 
      android:textColor="@color/colorButton" 
      android:layout_weight="1" /> 
      android:id="@+id/decr" 
      android:layout_weight="1" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_weight="1" > 


     <CheckBox 
      android:text="SL" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/sl" 
      android:textColor="#8c8181" 
      android:layout_weight="1" /> 

     <CheckBox 
      android:text="S" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/s" 
      android:textColor="#8c8181" 
      android:layout_weight="1" /> 
     <CheckBox 
      android:text="M" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/m" 
      android:textColor="#8c8181" 
      android:layout_weight="1" /> 

     <CheckBox 
      android:text="l" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/L" 
      android:textColor="#8c8181" 
      android:layout_weight="1" /> 

     <CheckBox 
      android:text="F" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/f" 
      android:textColor="#8c8181" 
      android:layout_weight="1" /> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_weight="1" > 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:background="#c0c0c0"/> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_weight="1" > 


     <Spinner 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/spinner1" 
      android:background="@drawable/spinner_bg" 
     android:layout_weight="1" /> 


     <Spinner 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/spinner2" 
      android:background="@drawable/spinner_bg" 
      android:layout_weight="1" /> 


    </LinearLayout> 



     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="5dp" 
      android:layout_weight="1" > 

      <TextView 
       android:text="TextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/textView2" 
       android:layout_weight="1" /> 


     </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_weight="1" > 



     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="hint" /> 
     </android.support.design.widget.TextInputLayout> 

    </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="5dp" 
      android:layout_weight="1" > 

      <Button 
       android:text="Cancel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/canc" 
       android:textColor="#ffffff" 
       android:background="@drawable/mybutton2" 
       android:layout_weight=".5" /> 
      <Button 
       android:text="Ok" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/ok" 
       android:textColor="#ffffff" 
       android:background="@drawable/mybutton" 
       android:layout_weight=".5" /> 



     </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

这里是我的子菜单活动,其中如果u点击一个项目,它会显示弹出

public class SubMenu extends AppCompatActivity { 

    JSONObject jsonobject; 
    JSONArray jsonarray; 
    ListView listview; 
    ListViewAdapter adapter; 
    ProgressDialog mProgressDialog; 
    ArrayList<HashMap<String, String>> arraylist; 
    static String RANK = "id"; 
    static String COUNTRY = "name"; 

    static String FLAG = "image"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 


     setContentView(R.layout.activity_sub_menu); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     String SelectedId = getIntent().getStringExtra("id"); 


     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 




     // Get the view from listview_main.xml 

     // Execute DownloadJSON AsyncTask 
     new DownloadJSON().execute(); 
    } 

    // DownloadJSON AsyncTask 
    private class DownloadJSON extends AsyncTask<Void, Void, Void> implements AdapterView.OnItemClickListener { 

     // @Override 
     // protected void onPreExecute() { 
     // super.onPreExecute(); 
     // Create a progressdialog 
     // mProgressDialog = new ProgressDialog(SubMenu.this); 
     // Set progressdialog title 
     // mProgressDialog.setTitle("Categories of Main categories....."); 
     // Set progressdialog message 
     // mProgressDialog.setMessage("Loading..."); 
     // mProgressDialog.setIndeterminate(false); 
     // Show progressdialog 
     // mProgressDialog.show(); 
     // } 

     @Override 
     protected Void doInBackground(Void... params) { 
      // Create an array 
      arraylist = new ArrayList<HashMap<String, String>>(); 
      // Retrieve JSON Objects from the given URL address 
      jsonarray = JsonFunctions 
        .getJSONfromURL("http://cloud.granddubai.com/broccoli/menu_typeitem.php?id=" + getIntent().getStringExtra("id")); 
      try { 
       // Locate the array name in JSON 
//     jsonarray = jsonobject.getJSONArray("main_menu_items"); 


       for (int i = 0; i < jsonarray.length(); i++) { 
        HashMap<String, String> map = new HashMap<String, String>(); 

        jsonobject = jsonarray.getJSONObject(i); 
        // Retrive JSON Objects 
        // map.put("id", jsonobject.getString("id")); 
        map.put("name", jsonobject.getString("name")); 

        map.put("image", jsonobject.getString("image")); 
        // Set the JSON Objects into the array 
        arraylist.add(map); 
       } 
      } catch (JSONException e) { 
       Log.e("Error", e.getMessage()); 
       e.printStackTrace(); 
      } 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void args) { 
      // Locate the listview in listview_main.xml 
      listview = (ListView) findViewById(R.id.list1); 
      // Pass the results into ListViewAdapter.java 
      adapter = new ListViewAdapter(SubMenu.this, arraylist); 
      // Set the adapter to the ListView 
      listview.setAdapter(adapter); 
      listview.setOnItemClickListener(this); 
      // Close the progressdialog 
      // mProgressDialog.dismiss(); 
     } 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      LayoutInflater layoutInflater 
        = (LayoutInflater)getBaseContext() 
        .getSystemService(LAYOUT_INFLATER_SERVICE); 
      View popupView = layoutInflater.inflate(R.layout.popup, null); 
      final PopupWindow popupWindow = new PopupWindow(
        popupView, 
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        ViewGroup.LayoutParams.WRAP_CONTENT); 

      Button btnDismiss = (Button)popupView.findViewById(R.id.canc); 
      btnDismiss.setOnClickListener(new Button.OnClickListener(){ 

       @Override 
       public void onClick(View v) { 
        popupWindow.dismiss(); 
       }}); 

      popupWindow.showAsDropDown(view, 3000, -90); 







     } 
    } 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case android.R.id.home: 
       onBackPressed(); 
       return true; 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 
} 
+0

发表您的XML布局 – Noorul

+0

你必须使用可绘为这种布局。即左圆形绘制,右圆绘制等 –

+0

我用它作为微调和按钮,但即时新的设计,特别是当做布局..如果你想要更多的文件,我会添加它..但请善待我的代码 –

回答

1

这个替换您的布局xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="10dp"> 

     <ImageView 
      android:id="@+id/desimage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:src="@drawable/logo" /> 

     <TextView 
      android:id="@+id/h1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:text="Chicken Pizza Small" 
      android:textSize="21sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/h2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:text="Chicken Pizza Small Combo" 
      android:textColor="#8c8181" 
      android:textSize="16sp" /> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="10dp" 
      android:orientation="horizontal" 
      android:weightSum="10"> 

      <Button 
       android:id="@+id/quant" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginRight="10dp" 
       android:layout_weight="3" 
       android:background="@drawable/mybutton" 
       android:text="Quantity" 
       android:textAllCaps="false" 
       android:textColor="#ffffff" /> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_weight="7" 
       android:background="@drawable/stroke_button" 
       android:orientation="horizontal" 
       android:weightSum="3"> 

       <Button 
        android:id="@+id/incr" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:background="@android:color/transparent" 
        android:text="-" 
        android:textColor="#FFA726" 
        android:textSize="25dp" /> 

       <View 
        android:layout_width="1dp" 
        android:layout_height="match_parent" 
        android:background="#c0c0c0" /> 

       <EditText 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:inputType="number" 
        android:text="5" /> 

       <View 
        android:layout_width="1dp" 
        android:layout_height="match_parent" 
        android:background="#c0c0c0" /> 

       <Button 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:background="@android:color/transparent" 
        android:text="+" 
        android:textColor="#FFA726" 
        android:textSize="25dp" /> 

      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp"> 

      <CheckBox 
       android:id="@+id/sl" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="SL" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/s" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="S" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/m" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="M" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/L" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="l" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/f" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="F" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

     </LinearLayout> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:background="#c0c0c0" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:orientation="horizontal"> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginRight="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/stroke_button" 
       android:orientation="vertical" 
       android:paddingBottom="5dp" 
       android:paddingTop="5dp"> 

       <Spinner 
        android:id="@+id/spinner1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="5dp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/stroke_button" 
       android:orientation="vertical" 
       android:paddingBottom="5dp" 
       android:paddingTop="5dp"> 

       <Spinner 
        android:id="@+id/spinner2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="5dp" /> 
      </LinearLayout> 
     </LinearLayout> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:text="SPECIAL INSTRUCTIONS" 
      android:textSize="16sp" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/stroke_button" 
      android:padding="@dimen/_10sdp"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@android:color/transparent" 
       android:gravity="top" 
       android:inputType="textCapSentences|textMultiLine" 
       android:lines="5" 
       android:maxLines="5" 
       android:padding="2dp" 
       android:textColor="#c0c0c0" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp"> 

      <Button 
       android:id="@+id/canc" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/mybutton2" 
       android:text="Cancel" 
       android:textColor="#ffffff" /> 

      <Button 
       android:id="@+id/ok" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/mybutton" 
       android:text="Ok" 
       android:textColor="#ffffff" /> 


     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

在你res/drawable添加这些XML:

mybutton.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:radius="25dp" /> 
    <solid android:color="#004D40" /> 
</shape> 

mybutton2.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:radius="25dp" /> 
    <solid android:color="#FFA726" /> 
</shape> 

stroke_button.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="#FFFFFF" /> 
    <corners android:radius="20dp" /> 
    <stroke 
     android:width="1dp" 
     android:color="#c0c0c0" /> 
</shape> 
+0

但那些增量和减量视图是按钮,而不是textView..how我们可以使这个 –

+0

增量和减量应该在编辑文本上完成。不在按钮上。 +和 - 仅适用于点击事件。您可以使用按钮的相同方式编写TextView的onClickListener。 –

+0

你的答案几乎只是需要一点帮助,如果我使该文本作为按钮和背景为白色,所以布局线也变得无形..我们尝试(m说abt incr decr btn) –

0

@ z.al

1)对于设定数量ü删除两个按钮,而不是两个按钮y ou简单地放两个TextView,所以现在你有Total 3 TextView(一个用于“ - ”,一个用于“Count”和一个用于“+”)。此Textview具有Linear作为父项,并且在Drawable XML的帮助下,您可以设置Background。

2)和微调需要实现定制微调

为正确的观点给予适当的空白和边距。

参考链接,自定义微调: “http://mrbool.com/how-to-customize-spinner-in-android/28286

+0

亲切取代我的代码与你的,我会更好 –

+0

我有文件的圆形微调,但所有的都不是第一个图像显示的方式....首先我想让所有看起来像第一张图像中显示的所有地方 –

+0

这就是我要求的因为我在布局中遇到了麻烦......如果你能做到这一点适当的然后它将是伟大的 –