效果圖
xml中
<LinearLayout
? ? xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:app="http://schemas.android.com/apk/res-auto"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical"
? ? tools:context="com.lwy.lpopupmenu.MainActivity">
? ? <RelativeLayout
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="48dp"
? ? ? ? android:background="#FF1895FF">
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/title_tv"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:layout_centerInParent="true"
? ? ? ? ? ? android:text="標(biāo)題"
? ? ? ? ? ? android:textColor="#ffffff"
? ? ? ? ? ? android:textSize="16sp"/>
? ? ? ? <ImageView
? ? ? ? ? ? android:id="@+id/menu_iv"
? ? ? ? ? ? android:layout_width="23dp"
? ? ? ? ? ? android:layout_height="23dp"
? ? ? ? ? ? android:layout_alignParentRight="true"
? ? ? ? ? ? android:layout_centerVertical="true"
? ? ? ? ? ? android:layout_marginRight="8dp"
? ? ? ? ? ? android:background="@mipmap/common_forward_normal"/>
? ? </RelativeLayout>
</LinearLayout>
Mactivity中
package com.example.popuwindow3;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.lwy.righttopmenu.MenuItem;
import com.lwy.righttopmenu.RightTopMenu;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity? {
? ? private Button mBt;
? ? private RightTopMenu mRightTopMenu;
? ? private View mMenuIV;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_main);
? ? ? ? mMenuIV = findViewById(R.id.menu_iv);
? ? ? ? mMenuIV.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? List<MenuItem> menuItems= new ArrayList<>();
? ? ? ? ? ? ? ? menuItems.add(new MenuItem(R.mipmap.multichat, "發(fā)起多人聊天", 100));
? ? ? ? ? ? ? ? menuItems.add(new MenuItem(R.mipmap.addmember, "加好友", 3));
? ? ? ? ? ? ? ? menuItems.add(new MenuItem(R.mipmap.qr_scan, "掃一掃"));
? ? ? ? ? ? ? ? menuItems.add(new MenuItem(R.mipmap.facetoface, "面對面快傳"));
? ? ? ? ? ? ? ? menuItems.add(new MenuItem(R.mipmap.pay, "付款"));
? ? ? ? ? ? ? ? if (mRightTopMenu == null) {
? ? ? ? ? ? ? ? ? ? mRightTopMenu = new RightTopMenu.Builder(MainActivity.this)
//? ? ? ? ? ? ? ? ? ? ? ? ? ? .windowHeight(480)? ? //當(dāng)菜單數(shù)量大于3個時,為wrap_content,反之取默認(rèn)高度320
//? ? ? ? ? ? ? ? ? ? ? ? .windowWidth(320)? ? ? //默認(rèn)寬度wrap_content
? ? ? ? ? ? ? ? ? ? ? ? ? ? .dimBackground(true)? ? ? ? ? //背景變暗魏宽,默認(rèn)為true
? ? ? ? ? ? ? ? ? ? ? ? ? ? .needAnimationStyle(true)? //顯示動畫腐泻,默認(rèn)為true
? ? ? ? ? ? ? ? ? ? ? ? ? ? .animationStyle(R.style.RTM_ANIM_STYLE)? //默認(rèn)為R.style.RTM_ANIM_STYLE
? ? ? ? ? ? ? ? ? ? ? ? ? ? .menuItems(menuItems)
? ? ? ? ? ? ? ? ? ? ? ? ? ? .onMenuItemClickListener(new RightTopMenu.OnMenuItemClickListener() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void onMenuItemClick(int position) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this, "點(diǎn)擊菜單:" + position, Toast.LENGTH_SHORT).show();
}
? ? ? ? ? ? ? ? ? ? ? ? ? ? }).build();
}
? ? ? ? ? ? ? ? mRightTopMenu.showAsDropDown(mMenuIV, 0, 0);
}
? ? ? ? });
}
}