Android中的自定义操作栏是否可能?

时间:2015-12-02 11:50:01

标签: android

很抱歉这个问题过于抽象,但我真的需要新鲜的想法。

我正在寻找一种方法,可以在Android的操作栏中放置多媒体键,音量增大和缩小以及其他几个控件。类似于系统操作栏(带有后退和主页按钮),我希望自定义的一个在所有其他应用程序的活动中始终可见。要使用的设备是根植的,这样可以使事情变得更容易。我主要专注于iOS开发,这就是我需要你帮助的原因。

如果有人有任何想法请分享。我只需要一个方向开始。

编辑:很抱歉,好像我没有被正确理解。我的意思是我想在每个应用程序之上设置一个操作栏。 (想象一下Facebook Messanger的泡沫)。

编辑2:已找到解决方案:Creating a system overlay window (always on top)

2 个答案:

答案 0 :(得分:1)

首先,你应该使用ToolBar。 创建xml文件

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        style="@style/CustomActionBar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">

        <ImageButton
            android:id="@+id/vol_plus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button_vol_plus_24dp"
            />
        <ImageButton
            android:id="@+id/vol_minus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button_vol_minus_24dp"
            />
        <ImageButton
            android:id="@+id/vol_mute"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button_vol_mute_24dp"
            />

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

</android.support.design.widget.AppBarLayout>

像这样,您可以在工具栏中添加控件,并可以附加在活动您还可以进行布局以获得更好的观看次数

答案 1 :(得分:0)

是的,您可以在活动顶部设置操作栏,只需在您要使用的活动中定义工具栏。

// tool bar xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar_action"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/ColorPrimaryDark"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
//inisde the xml
 <include
        android:id="@+id/toolbar_action"
        layout="@layout/toolbar" >
    </include>

//activity class
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);