【问题标题】:Spinner title should be an image and subtitle to be text微调标题应该是图像,副标题应该是文本
【发布时间】:2013-11-19 13:39:02
【问题描述】:

我使用操作栏。在其中使用微调器我希望它的标题应该是图像/图标,可选择的项目应该是文本,单击图标后它将显示字幕。我只想在操作栏中有图标以及点击图标时出现的下拉列表/微调器。有一个示例Spinner in action bar with only icon but not the selected option 但不能解决我的问题。我只想在操作栏中有图标和下拉列表/微调器点击图标时出现。Android 中的新功能。帮助我。

【问题讨论】:

    标签: android android-actionbar actionbarsherlock android-actionbar-compat


    【解决方案1】:

    在 setOnItemSelected 监听器上,

    你可以写

    if (((TextView) view) != null) {
            ((TextView) view).setText(null);
    }
    

    这样您将只显示图标而不显示文本。并将背景设置为您想要的可绘制图标。

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      您需要选择一个按钮并将任何图像设置为其背景。然后单击按钮调用 Spinner.performClick() 以打开微调器。

      以下是实现相同功能的代码。 在xml文件中:

           <Button
              android:id="@+id/font"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:layout_marginLeft="50dp"
              android:layout_weight="0.5"
              android:background="@drawable/textsel" /> 
      
           <Spinner
              android:id="@+id/spin"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              android:layout_marginLeft="10dp"
              android:layout_weight="0.5"
              android:dropDownHorizontalOffset="0dp"
              android:dropDownVerticalOffset="20dp"
              android:dropDownWidth="500dp"
              android:paddingTop="2sp"
              android:spinnerMode="dropdown" >
          </Spinner>
      

      在 Java 类中:

            Spinner spin = (Spinner) findViewById(R.id.spin);
      
            Button typetext = (Button) findViewById(R.id.font);      
      
      
            typetext.setOnClickListener(new OnClickListener() {
      
              @Override
              public void onClick(View v) {
      
                  spin.performClick();
      
              }
          });
      

      【讨论】:

        猜你喜欢
        • 2016-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多