我正在使用ActionBarSherlock使我的应用程序与旧设备兼容.实现很简单,但现在我需要将您在标签下看到的默认Holo蓝线设置为红线.
我一直在阅读SO上的一些主题(主题1,主题2)以及ABS文档(链接),但我无法让它工作.
这就是我到目前为止所拥有的.
在我的AndroidManifest.xml中,我将此行添加到application标记中.
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" > <!-- SET THE DEFAULT THEME -->
Run Code Online (Sandbox Code Playgroud)
然后在res/values/styles.xml我有:
<resources>
<style name="AppTheme" parent="android:Theme.Light" />
<style name="Theme.MyTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#ff000000</item>
<item name="background">#ff000000</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的应用程序时,我仍然看到默认的蓝线颜色.
我究竟做错了什么?
编辑
如果您想完全设计ActionBarSherlock样式,请阅读此内容!
我在SO上找到了一个答案,它提供了以下链接:http: //jgilfelt.github.com/android-actionbarstylegenerator
它是一个简单的发电机,可为完全定制的ABS生成所有需要的文件!您所要做的就是将生成的文件复制到适当的文件夹中,然后进行设置!
不要忘记在AndroidManifest中启用样式(您必须在生成器中输入样式名称).为此,请参阅下面的答案.
我有一个带有活动的应用程序和3个可跳转的标签(片段).我在选项卡中有一些大量创建的UI元素,需要一些时间才能创建,第一次运行就可以了,但每次刷卡时都会重新创建视图.
当我选择一个选项卡时,另一个选项卡调用onStop(),当我再次选择上一个选项卡时,再次调用onCreateView()并重新填充视图,这会减慢并阻止UI线程.
在标签ONCE内创建片段的正确方法是什么,并避免在其他标签之间滑动时重新创建视图?
我想修改下面标签的文字颜色:(ACCUEIL和A LA UNE)(现在是黑色).
我不知道该怎么做.

这是FragmentActivity的代码:
package com.app.myapp.MainFragment;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import com.app.myapp.R;
import com.app.myapp.activities.Recherche_act;
public class TabMainFragment extends FragmentActivity implements ActionBar.TabListener {
private ViewPager viewPager;
private TabMainFragmentAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "ACCUEIL", "A LA UNE" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Typeface parade …Run Code Online (Sandbox Code Playgroud) 在新的设计指南(向下滚动到底部)中,您可以看到标签在新材料设计中的外观.TabHost然而我仍然看起来非常Holo,没有底线动画,没有涟漪效果.这是我们必须自己实施的吗?
android android-tabhost android-tabs material-design android-5.0-lollipop
如何在Espresso测试中打开标签?我试着做Espresso.onView(ViewMatchers.withId(R.id.practice_results_tab)).perform(ViewActions.click());,但那不起作用.在该代码中,我打开了此选项卡的布局.有XML文件:
<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/practice_tabHost">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/practice_settings_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/practice_results_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
我应该使用什么ID来打开标签?
logcat中的错误:
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
at least 90 percent of the view's area is displayed to the user.
Target view: "LinearLayout{id=2131296384, res-name=practice_results_tab, visibility=GONE, width=0, height=0, has-focus=false, …Run Code Online (Sandbox Code Playgroud) 在我将应用程序移动到5.0之后,我不得不从基本选项卡转移到google开发人员提供的slidingTabLayout .
问题是,我无法弄清楚如何将两个按钮居中,使它们像旧的那样居中.顺便说一下,我不是在谈论风格,只是按钮的位置,共享相同数量的空间!为了清楚起见,我会发布一些图片:
我现在拥有的:

我期望得到的:

我的布局:
<LinearLayout 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:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"></include>
<com.maddogs.mymoney.views.SlidingTabLayout
android:id="@+id/requestSlideTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"></com.maddogs.mymoney.views.SlidingTabLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.maddogs.mymoney.RequestActivity" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
非常感谢你 !
我正在使用TabLayout和ViewPager
<android.support.v4.view.ViewPager
android:id="@+id/view_pager_social_profiles"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_social_profiles"
android:layout_width="match_parent"
android:layout_height="112dp"
app:tabContentStart="72dp"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
app:tabMode="scrollable"></android.support.design.widget.TabLayout>
Run Code Online (Sandbox Code Playgroud)
我想从屏幕中间开始选项卡内容,因此如果只有一个选项卡,它将与屏幕正中对齐(水平),并且所选选项卡将始终位于中心.
android android-layout android-viewpager android-tabs android-tablayout
我正在开发一个使用该ActionBarSherlock库的Android应用程序.在一个活动中,我使用选项卡式导航和折叠ActionBar(底部的操作项).
在此图片中,您可以看到Activity其当前状态:选项卡正在第二行中推送.

在下图中,您可以看到Activity我想要的方式:选项卡应位于顶行,而不是第二行.我已阅读ActionBar和ActionBarSherlock文档,但发现没有办法迫使这种行为.

这是当前的代码,用于创建ActionBar.
public class AdminActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab itemsTab = actionBar.newTab().setText(R.string.label_tab_items);
ActionBar.Tab usersTab = actionBar.newTab().setText(R.string.label_tab_users);
actionBar.addTab(itemsTab);
actionBar.addTab(usersTab);
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
android android-tabhost actionbarsherlock android-actionbar android-tabs
编辑最新的设计库解决了这个问题
编译'com.android.support:design:+'
我与工作TabLayout在两种情况下,PagerAdapter和FragmentStatePagerAdapter.在这两种情况下,当在页面之间滑动时,选项卡指示器会弹跳.单击选项卡以更改页面时,选项卡指示器不会反弹.
我不确定这是否是我的错误,这是一个已知问题,或指南的一部分.如果您需要更多代码,或者我将发布其他示例.
FragmentStatePagerAdapter
mViewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
LogMeal log = mLogMealAdapter.getItem(position);
return MealViewFragment.newInstance(log.getId());
}
@Override
public CharSequence getPageTitle(int position) { // Tab text
LogMeal logMeal1 = mLogMealAdapter.getItem(position);
String s;
if (logMeal1.getMealName().toString().trim().length() > 12) {
s = logMeal1.getMealName().substring(0, 12) + "..";
} else {
s = logMeal1.getMealName();
}
return s;
}
@Override
public int getCount() {
return mLogMealAdapter.getCount();
}
});
tabs.setTabTextColors(Color.parseColor("#80ffffff"), Color.parseColor("#ffffff"));
if (mLogMealAdapter.getCount() == 1) {
tabs.setTabMode(TabLayout.MODE_FIXED);
} else {
tabs.setTabMode(TabLayout.MODE_SCROLLABLE); …Run Code Online (Sandbox Code Playgroud)