【问题标题】:Popup With Text Only onOptionsItemSelected仅包含文本的弹出窗口 onOptionsItemSelected
【发布时间】:2015-04-27 07:37:15
【问题描述】:

我的 onOptionsItemSelected 下拉菜单中有一个“关于”选项卡,我希望在您点击“关于”时弹出框显示几行关于应用程序的文本信息

最好的方法是什么?

【问题讨论】:

  • 您可以使用或扩展 DialogFragment 类。
  • 感谢您为我指明了正确的方向

标签: java android android-layout dialog


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dip">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:text="@string/app_descrip"
    android:textColor="?android:attr/textColorPrimaryInverse" />

<TextView
    android:id="@+id/about_credits"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="20dip"
    android:textSize="16sp"
    android:text="@string/app_credits"
    android:autoLink="web"
    android:textColor="?android:attr/textColorPrimaryInverse" />

    </LinearLayout>

扩展布局

  protected void about() {

        View messageView = getLayoutInflater().inflate(R.layout.about, null, false);


    TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
    int defaultColor = textView.getTextColors().getDefaultColor();
    textView.setTextColor(defaultColor);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(R.drawable.app_icon);
    builder.setTitle(R.string.app_name);
    builder.setView(messageView);
    builder.create();
    builder.show();
}

在菜单点击时调用它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    相关资源
    最近更新 更多