标签: android-appcompat

如果我使用新的"V7 Appcompat库",我还需要"V4支持库",最低SDK = 7吗?

我正在从Action Bar Sherlock迁移到Action Bar compat.我删除了ABS,我有支持-v4-google地图,我收到了错误.我现在将v4直接添加到项目中以查看它是否解决,但我想知道:

如果库是冗余的或补充的话,我真的不明白文档吗?

感谢您的建议,指示等.

编辑:这是错误,使我添加v4与"外部jar ..."解决它.

The type android.support.v4.app.TaskStackBuilder$SupportParentable cannot be resolved. 
It is indirectly referenced from required .class files
Run Code Online (Sandbox Code Playgroud)

但是,如果你说我不应该添加v4,如果已经有v7我该怎么解释它到Eclipse?

相关帖子,解决方案是在这里添加v4.扩展ActionBarActivity时,类型活动的层次结构不一致

编辑2:如果按照以下步骤逐点完成,则v4 jar包含在v7库项目中:http://developer.android.com/tools/support-library/setup.html#add-library 我的设置是:

  • Android 4.3:未经检查
  • APrivate Lib:未经检查
  • v7-app .../src:选中
  • v7-app .../gen:已检查
  • ADependencie:未经检查
  • 原始v7 jar:检查
  • raw v4 jar:检查

android android-appcompat android-support-library

34
推荐指数
2
解决办法
3万
查看次数

AppCompat_v7工具栏作为操作栏不显示菜单中的"始终"操作,但API工具栏确实如此

在使用新的API 21工具栏和appCompat_v7两天后,我想我发现了一个错误.如果你的菜单上有2个动作,如下所示:

<item
    android:id="@+id/action_test"
    android:showAsAction="always"
    android:icon="@drawable/ic_launcher"
    android:title="@string/action_settings"/>

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
Run Code Online (Sandbox Code Playgroud)

和appCompat工具栏定义如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.toolbar.MainActivity" >

    <android.support.v7.widget.Toolbar 
        android:layout_width="match_parent"
        android:layout_height="52dp"
        android:id="@+id/toolbar">
    </android.support.v7.widget.Toolbar>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

膨胀后(或设置setSupportActionBar方法)

Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
toolbar.setTitle("esurance");
setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud)

您将获得没有操作图标的工具栏菜单,它将显示在溢出菜单上.

但是,如果您使用API​​ 21中的工具栏类,它将显示您在菜单布局中定义的操作...

<Toolbar 
    android:layout_width="match_parent"
    android:layout_height="52dp"
    android:id="@+id/toolbar">
</Toolbar>
Run Code Online (Sandbox Code Playgroud)

也许我在这里遗漏了一些东西,但到目前为止,我一直无法使用appCompat在溢出菜单之外显示操作.任何有关这方面的帮助将非常感激.

在此输入图像描述

android android-appcompat android-layout

34
推荐指数
1
解决办法
3万
查看次数

应用程序图标不会显示在操作栏上

我跟进了构建一个新的android项目的指示,除了操作栏的问题我得到了一个可运行的项目.问题是应用程序图标没有显示在操作栏上的应用程序标题旁边.我使用以下配置创建了项目:

  • 最低要求的SDK:API 8:Android 2.2(Froyo)

  • 目标SDK:API 21:Android 4.X(L预览版)

  • 编译:API 21:Android 4.X(L预览版)

  • 主题:Holo Light with Dark Action Bar(Eclipse设置相应的appcompat主题)

  • Android支持库21.0.1

  • Android SDK Build-tools 21.1.1

因为我的最小sdk是api 8,它不支持动作栏,所以项目包含一个appcompat_v7 library允许动作栏功能.如果我将最小sdk设置为api 14(android 4.0)或更高,那么项目不包括,appcompat_v7 library并且应用程序图标也显示成功.但我需要我的应用程序支持低至api 8的旧版本.所以我应该怎么做才能解决这个问题?真的很感谢你们的关注.

PS:我在windows,mac,eclipse,android studio上完成了上面的任务,得到了相同的结果.

icons android android-appcompat android-actionbar material-design

34
推荐指数
3
解决办法
5万
查看次数

如何在AppCompat下设置SearchView的光标颜色样式

我的SearchView是android.support.v7.widget.SearchView和AppTheme如下所示.

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/color_accent</item>
</style>

<style name="AppTheme" parent="AppBaseTheme">
</style>
Run Code Online (Sandbox Code Playgroud)

SearchView的颜色看起来很奇怪,它的光标和底线显示为白色并快速转换为强调色,如何处理呢?我想让光标和底线保持白色.

android android-appcompat android-styles

34
推荐指数
5
解决办法
2万
查看次数

在res文件夹的styles.xml中找不到app命名空间

我正在用android.support.v7.widget.Toolbar小部件编写自己的工具栏,我想尽可能多地放入res文件夹中的styles.xml.

/res/layout/$example.xml中文件的一部分

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/toolbar_show_addresses_simple"
    app:style="@style/toolbar_dark" >
Run Code Online (Sandbox Code Playgroud)

我的"toolbar_dark"在/res/values/styles.xml中定义如下

<style name="toolbar_dark">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:background">@color/myPrimary</item>
    <item name="app:theme">@style/ThemeOverlay.AppCompat.Dark</item>
    <item name="app:popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
    <item name="app:contentInsetStart">0dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

编译时

  Output:
     Error: No resource found that matches the given name: attr 'app:contentInsetStart'.
     Error: No resource found that matches the given name: attr 'app:popupTheme'.
     Error: No resource found that matches the given name: attr 'app:theme'.
Run Code Online (Sandbox Code Playgroud)

如果我直接在$ example.xml中使用app:*值,一切正常.因此,如何在res文件夹中的文件中使用我的app命名空间?

android android-appcompat android-studio

34
推荐指数
1
解决办法
1万
查看次数

当RecyclerView适合屏幕时,不要折叠工具栏


我使用Android Design Library创建了一个应用程序,带有工具栏和TabLayout.
实际上有2个选项卡,都有2个RecyclerView,滚动时会自动折叠工具栏.

我的问题是:当RecyclerView具有少量项目并完全适合屏幕时(如TAB 2中),我可以禁用工具栏折叠吗?

我见过很多像CheeseSquare这样的例子,由Google员工制作,问题仍然存在:即使RecyclerView只有1个项目,工具栏仍然隐藏在滚动上.

在此输入图像描述

我想我可以找出是否在屏幕上显示RecyclerView的第一项,如果是,则禁用工具栏折叠.前者易于实现,后者又如何呢?

这是我的布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
            android:background="?attr/colorPrimary"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/glucosio_pink"
            app:tabSelectedTextColor="@android:color/white"
            app:tabIndicatorColor="@color/glucosio_accent"
            app:tabTextColor="#80ffffff"/>
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/main_fab"
        android:layout_margin="16dp"
        android:onClick="onFabClicked"
        app:backgroundTint="@color/glucosio_accent"
        android:src="@drawable/ic_add_black_24dp"
        android:layout_gravity="bottom|right"
        />
    </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)




android toolbar android-appcompat android-recyclerview android-design-library

34
推荐指数
4
解决办法
1万
查看次数

如何使用AppCompat设置禁用的按钮颜色?

我使用这种风格来改变我的背景颜色Button:

<style name="AccentButton" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/colorAccent</item>
    <item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)

布局中:

    <Button
        android:id="@+id/login_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/fragment_login_login_button"
        app:theme="@style/AccentButton"/>
Run Code Online (Sandbox Code Playgroud)

有用.但是当我打电话setEnabled(false)给它时Button,它保持相同的颜色.我该如何处理这个案子?

android android-appcompat android-button

34
推荐指数
5
解决办法
3万
查看次数

操作栏未随AppCompat显示

我正在使用AppCompat将我的应用程序移植到API7,并且操作栏出现问题.

当我使用FragmentActivity动作栏时显示在我的手机上(API18),但是ActionBarActivity按下menubutton会显示为选项菜单.

在具有API7的模拟器上,操作栏始终显示为选项菜单.

有任何想法吗?

android android-appcompat android-actionbar android-actionbar-compat

33
推荐指数
2
解决办法
2万
查看次数

如何使用Appcompat v7 21,工具栏和DrawerLayout动画汉堡到箭头

我使用android.support.v7.widget.Toolbar与android.support.v4.widget.DrawerLayout.它工作正常,导航抽屉关闭时显示汉堡图标,抽屉打开时显示箭头图标.我想在应用程序中的某些事件中禁用抽屉并将Burger图标设置为箭头.我试图将锁定模式设置为关闭,但v7.app.ActionBarDrawerToggle仍显示Burger并打开抽屉.

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

有任何想法吗?谢谢!

更新:

不,我可以更改图标的状态,我可以启用/禁用抽屉,但动画不能使用此方法:

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    Toolbar toolbar = (Toolbar) findViewById(R.id.application_toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.string1, R.string.string2) {
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    //mDrawerLayout.setDrawerListener(mDrawerToggle); // not needed
    ...
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case android.R.id.home:
            if (mDrawerLayout.getDrawerLockMode(GravityCompat.START) == LOCK_MODE_UNLOCKED) {
                showDrawer();
            } else {
                handleBackButtonPress(); // On this stage the home button is …
Run Code Online (Sandbox Code Playgroud)

android toolbar android-appcompat drawerlayout drawertoggle

33
推荐指数
2
解决办法
4万
查看次数

PreferenceFragmentCompat在PreferenceCategory上有填充,我无法摆脱它

所以我一直在尝试使用androidx.preference.PreferenceFragmentCompat创建一个设置活动,它一切正常.

但是由于某种原因,在偏好类别和偏好本身上都存在一些填充.我设法通过使用app:iconSpaceReserved ="false"来摆脱首选项的填充,但这似乎不适用于类别.

图片

我已经尝试了所有各种主题,PreferenceThemeOverlay.v14.Material等但它们似乎没有什么区别

这是我的一切代码!

SettingsActivity.java

import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class SettingsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        Toolbar toolbar = findViewById(R.id.settings_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(false);
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

activity_settings.xml

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SettingsActivity">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/settings_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            style="@style/ToolbarTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title_settings"
            android:textColor="@color/font_dark_primary" />

    </androidx.appcompat.widget.Toolbar>

    <fragment
        android:name="com.henrytwist8gmail.fullcart.SettingsTestFragment"
        android:tag="settings_fragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/settings_toolbar" />

</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

SettingsTestFragment.java

import android.os.Bundle; …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat android-preferences preferencefragment androidx

33
推荐指数
4
解决办法
4742
查看次数