【问题标题】:set Actionbar height in SlidingTabsColors在 SlidingTabsColors 中设置操作栏高度
【发布时间】:2015-05-09 17:06:25
【问题描述】:

我正在使用SlidingTabsColors

如何设置操作栏高度?!我的意思是this image 中的灰色区域

这是操作栏吗?!!在这个项目中 MainActivity 是从 SampleActivityBase 扩展而来的,SampleActivityBase 是从 FragmentActivity 扩展而来的,所以它们不是从 ActionBarActivity 扩展而来的。

更新:

我将 activity_main 更改为以下代码:

<LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/sample_main_layout">

    <View
          android:layout_width="match_parent"
          android:layout_height="?android:attr/actionBarSize"
          android:background="@android:color/darker_gray" />

    <FrameLayout
          android:id="@+id/sample_content_fragment"
          android:layout_weight="2"
          android:layout_width="match_parent"
          android:layout_height="0px" />

</LinearLayout>

你可以在这里看到变化:

http://up.vbiran.ir/uploads/1851014311926138348_dffdff.png

【问题讨论】:

    标签: android


    【解决方案1】:

    我假设您在谈论包含 SlidingTabsColors 文本的灰色区域?

    此区域不是 ActionBar,这是在非常古老的 Android 应用中使用的标题。

    我强烈建议您使用最新的support libraries 和最新的appcompat library,然后在您的应用程序中使用Theme.AppCompat 样式。

    这将显示具有正确高度的真实ActionBar,并隐藏您在应用中看到的TitleBar


    要使用最新的 appcompat 库,请将以下内容添加到您的 build.gradle

    compile "com.android.support:appcompat-v7:22.1.1"
    

    在此之后将以下作为样式添加到您的活动(或应用程序)

    <application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher">
        <activity
            android:name=".Activity"
            android:theme="Theme.AppCompat"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        ....
    </application>
    

    【讨论】:

    • 谢谢,如何更改标签颜色?我的意思是背景不是分隔符
    • 作为背景,我会假设 android:background 属性通过 xml 或 setBackground 通过代码。不确定您在哪里定义其他颜色。
    【解决方案2】:
    <View
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
     />
    

    【讨论】:

    • 我用你的代码改变了 activity_main 但是:up.vbiran.ir/uploads/1851014311926138348_dffdff.png
    • 您需要将此应用到您的视图中,我的只是一个示例,请勿将其添加到您的 xml 中。
    • 问题是我不知道该查看哪个文件
    【解决方案3】:

    要在 XML 中获取 ActionBar 的高度,只需使用

    ?android:attr/actionBarSize
    

    你可以用它来设置这样的高度

    <View
        android:id="@+id/my_view"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
     />
    

    【讨论】:

    • 哪个xml文件? activity_main?
    • 你想在哪里设置actionbar的高度来查看
    • 我知道我的问题你能再检查一次吗?
    • 你想要什么可以再来吗?
    • 在 android 示例中检查 SlidingTabsColors 文件,我不知道我必须编辑哪个文件来设置操作栏高度
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    • 2022-01-24
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    相关资源
    最近更新 更多