首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将EditText放在操作栏中而不是标题上

将EditText放在操作栏中而不是标题上
EN

Stack Overflow用户
提问于 2014-12-26 08:29:05
回答 2查看 2.2K关注 0票数 1

是否可以将EditText添加到操作栏布局中?找不到这方面的任何信息。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-26 08:45:29

您可以为操作栏创建自定义视图。

下面是如何将定制布局充气并添加到您的ActionBar**.**中的

代码语言:javascript
运行
复制
 // Inflate your custom layout
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(
        R.layout.action_bar,
        null);

// Set up your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
// you can create listener over the EitText
final EditText actionBarText = (EditText) findViewById(R.id.action_bar_text);
actionBarText.addTextChangedListener(this);

这里有一个自定义布局:

代码语言:javascript
运行
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:orientation="horizontal"
android:paddingEnd="8dip" >

<EditText android:id="@+id/action_bar_text"
   <!-- don't forget to define the EditText style here  -->
/> 
</LinearLayout>

希望能帮上忙。

票数 2
EN

Stack Overflow用户

发布于 2014-12-26 08:34:42

是有可能..。您可以为custom View设置ActionBar

代码语言:javascript
运行
复制
    ActionBar actionBar = getActionBar();
    actionBar.setCustomView(R.layout.custom_actionbar_view);

有关更多信息,请查看此链接

http://www.sanfoundry.com/java-android-program-add-custom-view-actionbar/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27654703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档