gpt4 book ai didi

android - 如何分别收听 AppCompat 的工具栏 Logo /文本和后退导航项上的单击操作?

转载 作者:行者123 更新时间:2023-12-02 03:22:24 24 4
gpt4 key购买 nike

我对此完全迷失了。我怎样才能做到这一点?

最佳答案

您可以使用工具栏:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tool_bar"
android:background="@color/light_blue"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout android:id="@+id/action_home"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/touch_selector"
android:clickable="true"
android:padding="@dimen/small">
<ImageView
android:id="@+id/home_icon"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="@drawable/white_square_icon"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/home_icon"
android:text="My App"
android:textColor="@color/white_color"
android:layout_marginLeft="@dimen/small"
android:textSize="18sp" />
</RelativeLayout>

</android.support.v7.widget.Toolbar>

在你的代码中:

    Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
toolbar.findViewById(R.id.action_home).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

// custom implementation
}
});

并实现 OnClick()

关于android - 如何分别收听 AppCompat 的工具栏 Logo /文本和后退导航项上的单击操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32391072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com