标签: android-actionbaractivity

无法将Appcompat主题从光更改为全黑

我试图完全改变我的应用程序的主题,这是我修改和尝试的:

styles.xml 在values文件夹中

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

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

值-V11 styles.xml

<resources>

<!--
    Base application theme …
Run Code Online (Sandbox Code Playgroud)

java android android-appcompat android-theme android-actionbaractivity

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

如何将单个菜单项添加到android中的工具栏?

我只是想在工具栏的左侧有一个后退按钮.但是当我添加下面的代码时,会出现在toolbar的右侧.我可以将它更改为左侧吗?

我的代码

<menu 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" tools:context="com.me.myapp.activities.Timer">
    <item
        android:id="@+id/backButton"
        android:title="Back Button"
        android:icon="@mipmap/back_icon"
        app:showAsAction="ifRoom"></item>
</menu>
Run Code Online (Sandbox Code Playgroud)

android toolbar menuitem android-actionbaractivity android-toolbar

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

.getSupportActionBar在Fragment中不可用; 变通方法导致旋转时出现NullPointerException

结构体

(活动/碎片的名称已更改)

根据Android编程中的一些建议:The Big Nerd Ranch Guide,我有以下结构:

  • MyListFragment extends ListFragment
  • MyListActivity extends SimpleFragmentActivity
  • SimpleFragmentActivity extends ActionBarActivity

MyListActivity.java

public class MyListActivity extends SingleFragmentActivity {

    @Override
    protected Fragment createFragment() {
        return new MyListFragment();
    }
}
Run Code Online (Sandbox Code Playgroud)

SingleFragmentActivity.java

public abstract class SingleFragmentActivity extends ActionBarActivity {

    protected abstract Fragment createFragment ();

    @Override
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);

        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);

        if (fragment == null) {
            fragment = createFragment();
            fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit();
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat android-fragments android-actionbar-compat android-actionbaractivity

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

无法删除活动中的标题栏

我想在我的活动之上删除标题.我尝试了这两种方式,但不是在api级别8.

1:

<style name="NOtitleTheme" parent="Theme.AppCompat.Light">
<item name="android:windowFullscreen">true</item>
   <item name="android:windowNoTitle">true</item> </style>
Run Code Online (Sandbox Code Playgroud)

2:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)

知道为什么这不起作用api 8

一旦我设法删除它api 8,但我不记得如何.


编辑:

解决了!问题是 this.requestWindowFeature(Window.FEATURE_NO_TITLE)在API 8 <item name="android:windowNoTitle">true</item>上不起作用,也不起作用,但是 actionBar.hide()工作,getSupportActionBar()返回null的原因是之前使用了两个选项之一,我只是忘了删除它们.当我删除一个我添加其他(多么愚蠢!)谢谢所有!(抱歉英文不好)

android android-activity android-styles android-actionbaractivity

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

getSupportActionBar().setCustomView(view)不会填充整个操作栏

我正在尝试设置我的应用程序的自定义视图,我制作的布局没有填满整个操作栏.我尝试了很多样式设置,但没有一个适合我.

这是我的活动代码

View view = getLayoutInflater().inflate(R.layout.actionbar_customized_home, null);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(view);
Run Code Online (Sandbox Code Playgroud)

这里的布局设置为视图

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/actionbar_color"
    >
![enter image description here][1]

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:layout_centerInParent="true"
        android:scaleType="fitCenter"
        android:src="@drawable/logo"/>



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

甚至像导航器这样的菜单项的背景如何将我的自定义视图作为背景颜色?

我非常感谢你的帮助

android android-styles android-actionbar-compat android-actionbaractivity

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

具有自定义视图的扩展工具栏无法以全宽显示

我在这里找到了很多与工具栏相关的答案,但没有一个答案可以帮助我.

我想要实现的是有一个扩展的工具栏,它将显示一个徽标,可能是一个活动/应用程序的名称,它将有一个动作按钮/抽屉切换到右侧,将显示一个导航般的抽屉到右边是一个溢出菜单,其中包含其他选项,如设置和底部的导航标签,允许用户在不同的片段(一个月中的不同日期)之间移动.

我试图实现这一点的方式是通过工具栏.首先,我创建工具栏并添加我的自定义视图.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar_actionbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/min_double_toolbar_height"
        app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/primary"

        app:contentInsetStart="0dp"
        app:contentInsetEnd="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetRight="0dp"
        android:clipToPadding="false"
        >
        <!-- ThemeOVerlay Makes sure the text and items are using solid colors-->

        <include
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:layout_gravity="bottom"
            layout="@layout/day_navigation_tab"
            />

    </android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

day_navigation_tab只是一个水平的两个图像视图,其填充为72dp(如指南所示)和一个布局权重设置为1的文本视图,因此它会延伸整个可用空间.并且高度为72dp.

现在,在我的BaseActivity XML中,我将工具栏包含在主要上下文的Framelayout中(否则工具栏将覆盖整个屏幕,原因不明(对我而言,花了我很多时间)

<...ommited>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include
            android:id="@+id/toolbar"
            layout="@layout/app_bar"
            />
    </FrameLayout>

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         If …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-layout android-actionbaractivity android-toolbar

9
推荐指数
2
解决办法
9257
查看次数

必须在添加内容之前调用ActionBarActivity requestFeature

编辑反映matias's评论

实际上,最初我没有supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);在我的代码中,直到我注意到runtime exception when below combinations of actions happened

用户按下主页按钮以最小化应用程序并尝试从最近的应用程序(长按主页按钮)恢复它

当屏幕旋转发生时(注意:清单没有 configChange声明)

然后我认为在初始化期间显示不确定的进度条应该导致问题,所以只有我尝试调用request*方法,认为它会清除它,但没有发生任何事情..

最后我showPdIndeterminate();为了测试而删除了.因此,在我的代码中我无处可见.在上述情况下仍然发生同样的情况


我有一个片段ActionBarActivity,我的布局包裹在里面DrawerLayout,two framelayouts以容纳两个frgaments.

我尝试在super.onCreate上添加内容错误之前必须调用requestFeature(),但仍然是相同的异常

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.e(TAG, "Inside OnCreate");
    // supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    showPdIndeterminate();
           ....
}
Run Code Online (Sandbox Code Playgroud)

并且showPdIndeterminate()

private void showPdIndeterminate() {
    pd = ProgressDialog.show(this, "Initializing", "Pls wait...");
    pd.setIndeterminate(true);
    pd.show();
}
Run Code Online (Sandbox Code Playgroud)

NullPointerException如果我尝试supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); …

android android-fragments android-actionbaractivity

8
推荐指数
1
解决办法
2747
查看次数

使用Robolectric测试ActionBarActivity时出错

我正在使用Robolectric来测试我的应用程序中的活动.该活动扩展了ActionBarActivity.当我测试活动时,我得到错误:"IllegalStateException:你需要在这个活动中使用Theme.AppCompat主题(或后代)."

我的测试环境是:Android Studio 0.8.6,Robolectric 2.4-SNAPSHOT,support-v4库版本20.0,appcompat-v7版本20.0.

现在为班级.活动 :

public class FilterActivity extends ActionBarActivity
Run Code Online (Sandbox Code Playgroud)

测试类:

@Config(emulateSdk = 18, manifest = "src/main/AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class FilterActivityTest 
{
    private FilterActivity activity;

    @Before
    public void setUp() throws Exception
    {   
        activity = Robolectric.buildActivity(FilterActivity.class).create().get();
    }

    @After
    public void tearDown() throws Exception
    {
        activity.finish();
    }

    @Test
    public void testOnCreate()
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

我从values文件夹中的styles.xml:

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

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

堆栈跟踪:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
at …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat robolectric android-actionbaractivity

8
推荐指数
1
解决办法
1143
查看次数

为什么在ActionBarActivity上运行测试时会出现NoClassDefFoundError?

所以我使用Robotium,我的测试类正在扩展ActivityInstrumentationTestCase2该类.我已经在我的主项目中导入了v7支持库,并在测试项目中导入了库.

现在我不明白的是,当我将测试中的类更改为扩展Activity时,测试类正在工作,但是当我将其更改为ActionBarActivity它时返回一个NoClassDefFoundError.

我错过了什么吗?

这是我得到的日志

04-11 21:32:16.551: E/dalvikvm(23925): Could not find class 'com.example.project.ActivityClass', referenced from method com.example.project.tests.ActivityClass.<init>
Run Code Online (Sandbox Code Playgroud)

java android unit-testing robotium android-actionbaractivity

8
推荐指数
1
解决办法
386
查看次数

AppCompat v7工具栏向上/向后箭头不起作用

我在活动中有两个片段.当片段A显示时,我希望显示导航抽屉汉堡图标并使导航抽屉工作.当片段B显示时,我想要显示后退箭头以及何时单击它进行向上导航.但是,除非导航抽屉打开,否则我似乎无法使用新的AppCompat v7工具栏在ActionBarActivity中显示向上箭头.

在我的活动中,对于我的onCreate()方法,我有......

toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
    setSupportActionBar(toolbar);
}
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
Run Code Online (Sandbox Code Playgroud)

然后我打电话给mDrawerToggle.syncState();我的onPostCreate()

我试过搜索如何以编程方式触发工具栏图标到后箭头,但没有任何工作.从我收集到的,呼唤

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
Run Code Online (Sandbox Code Playgroud)

从我的片段应该改变图标,但事实并非如此.这可能是一个愚蠢的问题,但我做错了什么?

android android-fragments android-actionbar android-actionbaractivity android-toolbar

7
推荐指数
1
解决办法
7865
查看次数