相关疑难解决方法(0)

更改操作栏中的溢出图标

是否可以更改操作栏中的溢出图标?我有所有ActionBar项目的蓝色图标,我还想在出现时更改溢出图标.

android android-3.0-honeycomb android-4.0-ice-cream-sandwich android-actionbar

110
推荐指数
4
解决办法
6万
查看次数

OnGlobalLayoutListener:弃用和兼容性

我必须使用一个OnGlobalLayoutListener对象,然后删除监听器,我有一个问题与我用以下代码解决的弃用方法.

protected void onCreate(Bundle savedInstanceState) {
    final LinearLayout llTotal = (LinearLayout) findViewById(R.id.mmc_ll);
    ViewTreeObserver vto = llTotal.getViewTreeObserver();
    if(vto.isAlive()){
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                //
                // mycode
                //
                if (Build.VERSION.SDK_INT<16) {
                    removeLayoutListenerPre16(llTotal.getViewTreeObserver(),this);
                } else {
                    removeLayoutListenerPost16(llTotal.getViewTreeObserver(), this);
                }
            } 
        });
    }
    super.onCreate(savedInstanceState);
}

@SuppressWarnings("deprecation")
private void removeLayoutListenerPre16(ViewTreeObserver observer, OnGlobalLayoutListener listener){
    observer.removeGlobalOnLayoutListener(listener);
}

@TargetApi(16)
private void removeLayoutListenerPost16(ViewTreeObserver observer, OnGlobalLayoutListener listener){
    observer.removeOnGlobalLayoutListener(listener);
}
Run Code Online (Sandbox Code Playgroud)

这是对的吗?有更好的方法来处理兼容性?

使用API​​ 10在模拟器中运行代码我在LogCat中有以下警告

04-24 09:30:12.565: I/dalvikvm(471): Could not find method android.view.ViewTreeObserver.removeOnGlobalLayoutListener, referenced from method com.my.project.ActivityHome.removeLayoutListenerPost16
04-24 …
Run Code Online (Sandbox Code Playgroud)

compatibility android deprecated

72
推荐指数
5
解决办法
4万
查看次数

我什么时候可以先测量视图?

所以我在尝试设置视图的背景可绘制时有点混乱.该代码依赖于知道视线的高度,所以我不能把它onCreate()onResume(),因为getHeight()返回0 onResume()似乎是最接近我可以得到虽然.我应该在哪里放置如下所示的代码,以便在显示给用户时背景发生变化?

    TextView tv = (TextView)findViewById(R.id.image_test);
    LayerDrawable ld = (LayerDrawable)tv.getBackground();
    int height = tv.getHeight(); //when to call this so as not to get 0?
    int topInset = height / 2;
    ld.setLayerInset(1, 0, topInset, 0, 0);
    tv.setBackgroundDrawable(ld);
Run Code Online (Sandbox Code Playgroud)

height layout android android-lifecycle

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

更改ActionBar上溢出按钮的颜色

是否可以更改操作栏上的溢出按钮(3个垂直点)的颜色?如果是这样,我们该怎么做?我没有找到溢出按钮的任何样式.

谢谢

android android-actionbar

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

Android Lollipop Material Design溢出菜单图标颜色

我在Nexus 7上尝试新的Material Design,并且有以下奇怪的行为.第一个应用程序启动时,溢出菜单图标具有不同的颜色.

我改变了android:textColorPrimary颜色并阅读了本教程.

  1. 首次推出应用:首次推出应用

  2. 第二次应用推出:在此输入图像描述

如您所见,首次启动时未设置主要文本颜色的颜色.仅在我按下主页按钮并重新启动应用程序时才会设置.这是我的styles.xml档案:

<style name="AppBaseTheme" parent="android:Theme.Material.Light">
    <item name="android:colorPrimary">#FF4444</item>
    <item name="android:colorPrimaryDark">#CC0000</item>
    <item name="android:textColorPrimary">#000000</item>
</style>
Run Code Online (Sandbox Code Playgroud)

有人可以解释,为什么会出现这种行为?

我设置android:minSdkVersion="21"并且不想使用支持库.

java xml android material-design android-5.0-lollipop

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

更改ActionMode溢出图标

有没有办法更改ActionMode Overflow图标而不更改"普通"ActionBar的图标?

android android-actionbar android-actionmode

6
推荐指数
2
解决办法
5855
查看次数

以编程方式设置工具栏图标颜色

如何设置的图标(家庭和溢出菜单图标)的颜色在Toolbar/ AppBarLayout 编程

我想更改活动中单个片段的工具栏颜色方案.将AppBarLayout背景设置为浅色(例如浅灰色appBarLayout.setBackgroundResource(..);)会产生白色图标和白色标题,几乎看不到.

其布局如下:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:theme="@style/ToolbarStyle"
        app:layout_scrollFlags="scroll|enterAlways"/>

</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

找到解决方案

android material-design android-toolbar android-appbarlayout

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

如何自定义Action Bar Style?

如何更改操作栏后退按钮和操作栏菜单图标(附加图像)的颜色.我有以下样式代码(下面),使用它我自定义文本但我无法完全自定义操作栏.

下面是我使用的样式代码:

<style name="MyCustomTheme" parent="Theme.Sherlock.Light">

     <item name="actionBarStyle">@style/ActionBar</item>

     <item name="android:actionBarStyle">@style/ActionBar</item>

     </style>

 <style name="ActionBar" parent="Widget.Sherlock.ActionBar">
        <item name="background">@drawable/bg_header</item> -----------(1)
        <item name="android:background">@drawable/bg_header</item>

        <item name="android:titleTextStyle">@style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item> ----(2)
        <item name="titleTextStyle">@style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item>
         <item name="android:homeAsUpIndicator">@style/customTextAppearance.Sherlock.Widget.ActionBar.Title</item>
    </style>


 <style name="customTextAppearance.Sherlock.Widget.ActionBar.Title" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
        <item name="android:textSize">18dp</item>
        <item name="android:textColor">#ffffff</item>
        <item name="android:shadowColor">#ffffff</item>
        <item name="android:shadowDy">3</item>
        <item name="android:textStyle">bold</item>

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

感谢您的帮助,谢谢. 屏幕截图

android android-actionbar

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