Android ActionBarDrawerToggle以ActionBar的方式
我正在尝试在我的布局中实现一个自定义的Android ActionBarDrawerToggle以ActionBar的方式,android,android-layout,android-actionbar,Android,Android Layout,Android Actionbar,我正在尝试在我的布局中实现一个自定义的操作栏(包含渐变),该布局支持导航抽屉片段。在用XML构建了一个自定义的ActionBar布局之后,我测试了我的应用程序,结果如下 如您所见,渐变不是从最右边开始的。它在ActionBarDrawerToggle(NavigationDrawerFragment的汉堡”菜单按钮)之后启动我希望渐变从屏幕的最左边到最右边。 到目前为止,我的情况如下: private void showGlobalContextActionBar() { action
操作栏
(包含渐变),该布局支持导航抽屉片段
。在用XML构建了一个自定义的ActionBar
布局之后,我测试了我的应用程序,结果如下
如您所见,渐变不是从最右边开始的。它在ActionBarDrawerToggle
(NavigationDrawerFragment
的汉堡”菜单按钮)之后启动我希望渐变从屏幕的最左边到最右边。
到目前为止,我的情况如下:
private void showGlobalContextActionBar()
{
actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setLogo(new ColorDrawable(Color.TRANSPARENT));
LayoutInflater inflater = this.getActivity().getLayoutInflater();
View actionBarLayout = (View) inflater.inflate(R.layout.action_bar, null);
// Gradient
final View gradientView = actionBarLayout.findViewById(R.id.actionbar_gradient);
PaintDrawable p = EricssonGradient.getActionBarGradient(gradientView);
gradientView.setBackground(p);
// Title
titleView = (TextView) actionBarLayout.findViewById(R.id.title);
titleView.setTypeface(app.getFont());
titleView.setText(res.getString(R.string.menu_title));
// Profile icon
ImageView profileIcon = (ImageView) actionBarLayout.findViewById(R.id.icon_profile);
profileIcon.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if(app.isLoggedIn())
{
// Find and select the PROFILE fragment
int profilePos = app.getFragmentPosition(ACDC.FRAGMENT_PROFILE);
selectItem(profilePos);
}
}
});
//assign the view to the actionbar
actionBar.setCustomView(actionBarLayout);
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:layout_gravity="fill_horizontal"
android:orientation="vertical">
<View
android:id="@+id/actionbar_gradient"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@drawable/horizontal_progress_bar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:gravity="center"
android:textSize="22sp"
android:maxLines="1"
android:textColor="#000"
android:ellipsize="end"
android:layout_weight="4"/>
<ImageView
android:minWidth="50dp"
android:id="@+id/icon_profile"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:gravity="center"
android:src="@drawable/icon_profile"
android:contentDescription="@string/action_profile"
android:layout_weight="1"
android:background="#EFEDEE"/>
</LinearLayout>
</LinearLayout>