简体   繁体   English

弹出菜单或微调器

[英]PopUp Menu or Spinner

Anyone know what the text alignment buttons found on Google Sheets look like?有人知道 Google Sheets 上的文本对齐按钮是什么样的吗?

Clicking on the button opens a popup with the 4 icons to align the text单击按钮会打开一个带有 4 个图标的弹出窗口以对齐文本

Thanks谢谢

Thanks谢谢

Your question is not clear enough but if I understand you right and you want to have a popup with 4 buttons, you can create a custom dialog which popups with the 4 icons or less as you wish.你的问题不够清楚,但如果我理解你的意思,并且你想要一个带有 4 个按钮的弹出窗口,你可以创建一个自定义对话框,根据需要弹出 4 个或更少的图标。

Here is the way:这是方法:

First create custom_dialog.xml首先创建custom_dialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:background="@drawable/custom_dialog_border"
    android:orientation="vertical">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:padding="@dimen/dimen5dp"
        android:text="@string/choose_language"
        android:textColor="@color/white"
        android:textSize="20sp" />

    <View
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen1dp"
        android:layout_marginBottom="@dimen/dimen10dp"
        android:background="@color/gray" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_marginBottom="5dp">

        <Button
            android:id="@+id/txtEnglish"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|start"
            android:layout_margin="5dp"
            android:background="@color/white"
            android:padding="@dimen/dimen5dp"
            android:text="@string/english"
            android:textAllCaps="false"
            android:enabled="false"
            android:textColor="@color/colorPrimary" />

        <Button
            android:id="@+id/txtArabic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|end"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:text="@string/arabic"
            android:background="@color/white"
            android:textAllCaps="false"
            android:textColor="@color/colorPrimary" />
    </FrameLayout>
</LinearLayout>

Then use your custom layout in java files然后在 java 文件中使用您的自定义布局

private void showCustomAlertDialog() {
     final Dialog dialog = new Dialog(AccountActivity.this);
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
     dialog.setContentView(R.layout.custom_dialog);
    
     Button english = dialog.findViewById(R.id.txtEnglish);
     Button arabic = dialog.findViewById(R.id.txtArabic);
    
     english.setOnClickListener(v -> {
          // do something
          dialog.cancel();
     });
    
     arabic.setOnClickListener(v -> {
         // do something
         dialog.cancel();
     });
    
     dialog.show();
 }

Finally call you custom dialog wherever you want (inside your button or menu item or something else)最后在任何你想要的地方调用你的自定义对话框(在你的按钮或菜单项或其他东西内)

showCustomAlertDialog();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM