1

在棉花糖之下,我们得到了副本/过去(感谢上帝)的顶部操纵杆的骑行,而我们有一个浮动操作栏。我现在的问题是如何定制我的动作条的浮动是黑暗的,而不是白色的背景和文本颜色(不改变我的应用程序的全部主题,那就是Theme.material.light.NoactionBar)如何自定义浮动ActionBar的背景?

enter image description here

回答

0

试试这个:

fab.setBackgroundTintList(ColorStateList.valueOf(ContextComp‌​at.getColor(getActiv‌​ity(), R.color.yellow))); 
+0

是什么晶圆厂改变从活动类中的背景是什么?如何以及在哪里找到它?是否有可能在styles.xml中做到这一点? – loki

1

我认为这是不可能的。经过很长时间的挖掘android源代码,我发现工具栏实现了一个android内部类com.android.internal.widget.FloatingToolbar.FloatingToolbarPopup

弹出容器由命名为com.android.internal.R.layout.floating_popup_container其中使用此背景机器人布局充气:背景= “ATTR/floatingToolbarPopupBackgroundDrawable?”

似乎没有办法从xml样式设置属性floatingToolbarPopupBackgroundDrawable。

但是你可以通过使用Java反射

@Override 
public void onActionModeStarted(ActionMode mode) 
{ 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
    { 
     try 
     { 
      Field field = mode.getClass().getDeclaredField("mFloatingToolbar"); 
      field.setAccessible(true); 
      Object mFloatingToolbar = field.get(mode); 
      field = mFloatingToolbar.getClass().getDeclaredField("mPopup"); 
      field.setAccessible(true); 
      Object mPopup = field.get(mFloatingToolbar); 
      field = mPopup.getClass().getDeclaredField("mContentContainer"); 
      field.setAccessible(true); 
      ViewGroup mContentContainer = (ViewGroup)field.get(mPopup); 
      mContentContainer.setBackgroundColor(Color.RED); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
    super.onActionModeStarted(mode); 
}