微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Android 的自定义操作栏中添加文本

如何解决如何在 Android 的自定义操作栏中添加文本

我可以创建一个带有自定义后退按钮的操作栏:

// Calling the action bar
ActionBar actionBar = getSupportActionBar();

// Customize the back button
actionBar.setHomeAsUpIndicator(R.drawable.ic_baseline_arrow_back_24);

// Showing the back button in action bar
actionBar.setdisplayHomeAsUpEnabled(true);

我现在不确定的是,我希望在同一个操作栏中(靠近操作栏的末尾)添加一个 TextView,但我不清楚我该怎么做?

我还需要在 TextView 上添加一个 onClickListened ,因为我希望它在用户点击它时执行一个操作。

谁能告诉我如何实现这一目标?

解决方法

actionbar.setTitle 会改变标题。 如果您想自定义它,使用工具栏会更好。你能举一个更详细的例子来说明你想要达到的目标吗。

,

如果我没猜错,您正在尝试在 ActionBar 中添加一个 TextView,这是不可能的。另一种方法是使用工具栏。

在您的工具栏中添加一个 ViewGroup(例如 LinearLayout、RelativeLayout 等)并在该 ViewGroup 中定义您的 TextView。

代码示例

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="section-1-questions">
  <div style="background-color:greenyellow;"> <b>Section 1:</b> </div><br>
  <fieldset class="form-group">
    <div class="row1">
      <div class="question1">
        <legend id="q1" class="col-form-label col-sm-8 pt-0"><b>1) Question 1</b></legend>
        <div class="col-sm-10 answers">
        </div>
      </div>
    </div>
  </fieldset>
  <fieldset class="form-group">
    <div class="row1">
      <legend id="q2" class="col-form-label col-sm-8 pt-3"><b>2) Question 2</b></legend>
      <div class="col-sm-10 answers">
      </div>
    </div>
  </fieldset>
  <fieldset class="form-group">
    <div class="row1">
      <legend id="q3" class="col-form-label col-sm-8 pt-3"><b>3) Question 3</b></legend>
      <div class="col-sm-10 answers">
      </div>
    </div>
  </fieldset>
  <fieldset class="form-group">
    <div class="row1">
      <legend id="q4" class="col-form-label col-sm-8 pt-3"><b>4) Question 4</b></legend>
      <div class="col-sm-10 answers">
      </div>
    </div>
  </fieldset>
  <fieldset class="form-group">
    <div class="row1">
      <legend id="q5" class="col-form-label col-sm-8 pt-3"><b>5) QUESTION 5</b></legend>
      <div class="col-sm-10 answers">
      </div>
    </div>
  </fieldset>
  <div class="form-group">
    <label for="remarks"><b>Remarks / Observations </b></label>
    <input type="name" class="form-control" name="Remarks1" id="remarks1" aria-describedby="nameHelp" placeholder="Please enter your Remarks / Observations">
    <small id="nameHelp" class="form-text text-muted">Please enter your Remarks / Observations about these questions.</small>
  </div>
</div>
<br>
<a class="btn btn-primary btnPrevious">Previous</a>
<a class="btn btn-primary btnNextS1">Next</a>
</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。