fixed action bar theme
This commit is contained in:
parent
bf30ed5a35
commit
a8ab005aae
|
@ -1268,4 +1268,22 @@ public class ThemeUtils implements Constants {
|
|||
return ((LinkHandlerActivity) activity).peekActionBarToolbar();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Context getActionBarThemedContext(Context base) {
|
||||
final TypedValue outValue = new TypedValue();
|
||||
final Resources.Theme baseTheme = base.getTheme();
|
||||
baseTheme.resolveAttribute(android.support.v7.appcompat.R.attr.actionBarTheme, outValue, true);
|
||||
|
||||
if (outValue.resourceId != 0) {
|
||||
final Resources.Theme actionBarTheme = base.getResources().newTheme();
|
||||
actionBarTheme.setTo(baseTheme);
|
||||
actionBarTheme.applyStyle(outValue.resourceId, true);
|
||||
|
||||
final Context actionBarContext = new android.support.v7.internal.view.ContextThemeWrapper(base, 0);
|
||||
actionBarContext.getTheme().setTo(actionBarTheme);
|
||||
return actionBarContext;
|
||||
} else {
|
||||
return base;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import android.support.v7.app.ActionBar;
|
|||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.app.AppCompatDelegateTrojan;
|
||||
import android.support.v7.internal.app.WindowDecorActionBar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.InflateException;
|
||||
import android.view.View;
|
||||
|
@ -167,7 +166,7 @@ public class ThemedLayoutInflaterFactory implements LayoutInflaterFactory {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean isActionBarContext(Context context, Context actionBarContext) {
|
||||
private static boolean isActionBarContext(@NonNull Context context, @Nullable Context actionBarContext) {
|
||||
if (actionBarContext == null) return false;
|
||||
if (context == actionBarContext) return true;
|
||||
Context base = context;
|
||||
|
@ -179,20 +178,21 @@ public class ThemedLayoutInflaterFactory implements LayoutInflaterFactory {
|
|||
|
||||
@Nullable
|
||||
private static Context getActionBarContext(@NonNull Activity activity) {
|
||||
Context actionBarContext = null;
|
||||
if (activity instanceof AppCompatActivity) {
|
||||
final AppCompatDelegate delegate = ((AppCompatActivity) activity).getDelegate();
|
||||
final ActionBar actionBar = AppCompatDelegateTrojan.peekActionBar(delegate);
|
||||
if (actionBar instanceof WindowDecorActionBar)
|
||||
return actionBar.getThemedContext();
|
||||
if (actionBar != null) {
|
||||
actionBarContext = actionBar.getThemedContext();
|
||||
}
|
||||
} else if (activity instanceof AppCompatPreferenceActivity) {
|
||||
final AppCompatDelegate delegate = ((AppCompatPreferenceActivity) activity).getDelegate();
|
||||
final ActionBar actionBar = AppCompatDelegateTrojan.peekActionBar(delegate);
|
||||
if (actionBar instanceof WindowDecorActionBar)
|
||||
return actionBar.getThemedContext();
|
||||
} else {
|
||||
final android.app.ActionBar actionBar = activity.getActionBar();
|
||||
if (actionBar != null) return actionBar.getThemedContext();
|
||||
if (actionBar != null) {
|
||||
actionBarContext = actionBar.getThemedContext();
|
||||
}
|
||||
}
|
||||
if (activity != actionBarContext) return actionBarContext;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.content.Context;
|
|||
import android.content.res.Resources;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.app.AppCompatCallback;
|
||||
import android.support.v7.internal.view.ContextThemeWrapper;
|
||||
import android.support.v7.internal.view.StandaloneActionMode;
|
||||
import android.support.v7.internal.view.SupportActionModeWrapper;
|
||||
import android.support.v7.internal.widget.ActionBarContextView;
|
||||
|
@ -115,7 +114,7 @@ public class TwidereActionModeForChildListener implements NativeActionModeAwareL
|
|||
final Resources.Theme baseTheme = mActivity.getTheme();
|
||||
baseTheme.resolveAttribute(android.support.v7.appcompat.R.attr.actionBarTheme, outValue, true);
|
||||
|
||||
final Context actionBarContext = getActionBarThemedContext();
|
||||
final Context actionBarContext = ThemeUtils.getActionBarThemedContext(mActivity);
|
||||
|
||||
mActionModeView = new ActionBarContextView(actionBarContext);
|
||||
mActionModePopup = new PopupWindow(actionBarContext, null,
|
||||
|
@ -170,25 +169,6 @@ public class TwidereActionModeForChildListener implements NativeActionModeAwareL
|
|||
return mActionMode;
|
||||
}
|
||||
|
||||
private Context getActionBarThemedContext() {
|
||||
final TypedValue outValue = new TypedValue();
|
||||
final Resources.Theme baseTheme = mActivity.getTheme();
|
||||
baseTheme.resolveAttribute(android.support.v7.appcompat.R.attr.actionBarTheme, outValue, true);
|
||||
|
||||
if (outValue.resourceId != 0) {
|
||||
final Resources.Theme actionBarTheme = mActivity.getResources().newTheme();
|
||||
actionBarTheme.setTo(baseTheme);
|
||||
actionBarTheme.applyStyle(outValue.resourceId, true);
|
||||
|
||||
final Context actionBarContext = new ContextThemeWrapper(mActivity, 0);
|
||||
actionBarContext.getTheme().setTo(actionBarTheme);
|
||||
return actionBarContext;
|
||||
} else {
|
||||
return mActivity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean finishExisting() {
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.internal.widget.ActionBarContainer;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/4/28.
|
||||
*/
|
||||
public class TwidereActionBarContainer extends ActionBarContainer {
|
||||
public TwidereActionBarContainer(Context context) {
|
||||
super(wrapContext(context));
|
||||
}
|
||||
|
||||
public TwidereActionBarContainer(Context context, AttributeSet attrs) {
|
||||
super(wrapContext(context), attrs);
|
||||
}
|
||||
|
||||
private static Context wrapContext(Context context) {
|
||||
return ThemeUtils.getActionBarThemedContext(context);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
|
@ -18,27 +17,25 @@
|
|||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<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:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
tools:layout_height="?android:actionBarSize">
|
||||
tools:layout_height="?actionBarSize">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/account_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="@dimen/element_spacing_small"
|
||||
android:layout_weight="0"
|
||||
tools:listitem="@layout/spinner_item_account_icon" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_toRightOf="@+id/account_spinner"
|
||||
android:padding="@dimen/element_spacing_small">
|
||||
|
||||
<EditText
|
||||
|
@ -65,4 +62,4 @@
|
|||
android:src="@drawable/ic_action_search" />
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -35,11 +35,11 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.internal.widget.ActionBarContainer
|
||||
<org.mariotaku.twidere.view.TwidereActionBarContainer
|
||||
android:id="@+id/twidere_action_bar_container"
|
||||
style="?attr/actionBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:layout_alignParentTop="true"
|
||||
android:gravity="top"
|
||||
android:touchscreenBlocksFocus="true"
|
||||
|
@ -60,7 +60,7 @@
|
|||
android:theme="?attr/actionBarTheme"
|
||||
android:visibility="gone" />
|
||||
|
||||
</android.support.v7.internal.widget.ActionBarContainer>
|
||||
</org.mariotaku.twidere.view.TwidereActionBarContainer>
|
||||
|
||||
<View
|
||||
android:id="@+id/window_overlay"
|
||||
|
|
Loading…
Reference in New Issue