gpt4 book ai didi

android - 操作栏 : Best practice for older Android versions

转载 作者:可可西里 更新时间:2023-11-01 18:45:40 26 4
gpt4 key购买 nike

我希望在我的应用程序顶部有一个菜单栏 - 就像 Facebook、Google+ 或 Twitter 一样:

这是显示此栏的 Twitter 应用程序的屏幕截图:它显示在每个 Activity 中,左侧有公司 Logo (可点击),右侧有 1-3 个菜单项(可点击图像)。

enter image description here

在GDCatalog应用中也可以看到:

enter image description here

因此对于该操作栏有一些要求:

  • 它也必须适用于较旧的 Android 平台,例如 API 级别 8。
  • 它必须在每个 Activity 中都可用,而无需一次又一次地重复代码。
  • 它必须适应屏幕尺寸以占据整个宽度。

实现此类操作栏的最佳做法是什么?

GreenDroid 就是这样做的(使用合并):

<?xml version="1.0" encoding="utf-8"?>

<!--
/*
** Copyright (C) 2010 Cyril Mottier (http://www.cyrilmottier.com)
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<merge
xmlns:android="http://schemas.android.com/apk/res/android">

<ImageButton
xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/gdActionBarItemStyle"
android:id="@+id/gd_action_bar_item"
android:layout_height="fill_parent"
android:scaleType="center" />

<ImageView
android:layout_width="?attr/gdActionBarDividerWidth"
android:layout_height="fill_parent"
android:background="?attr/gdActionBarDividerDrawable" />

<TextView
style="?attr/gdActionBarTitleStyle"
android:id="@+id/gd_action_bar_title"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:gravity="left|center_vertical"
android:singleLine="true"
android:textColor="?attr/gdActionBarTitleColor"
android:textSize="16sp"
android:textStyle="bold"
android:paddingRight="10dp"
android:paddingLeft="10dp" />

</merge>

这是一个好的解决方案吗?它也适用于旧平台吗?这里还缺少哪些编码部分?

我知道我们可以在这里找到关于这些操作栏的几个问题。但是,尽管如此,我还是找不到实现跨(几乎)所有 API 级别工作的菜单栏的最佳和最简单方法。是Google's solution也许是最好的?

提前致谢!

最佳答案

您可能想查看 ActionBarSherlock .源代码可用here .它会让你了解它是如何与 fragment 一起使用的。它会给你一些关于如何继续的想法。

Google 创建了一个 android 兼容性库,以使用他们为 honeycomb 创建的一些新 API,例如 1.5 及更高版本。它可以在 android sdk 文件夹中找到,例如 E:\Program Files\Android\android-sdk-windows\android-compatibility\v4\android-support-v4.jar。如果您没有此 jar,则需要使用 avd 管理器下载它。

关于android - 操作栏 : Best practice for older Android versions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7355831/

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