我一直在搜索互联网(例如Android文档,这里的答案等),以获得我认为是一个相当微不足道的问题的答案.您如何实现像Google音乐和YouTube中的半透明操作栏(链接是图像示例)?
我希望视频内容是全屏的,不受操作栏的约束/推送,同时仍然利用内置UI组件的优势.我显然可以使用完全自定义的视图,但如果可能的话,我宁愿利用ActionBar.
表现
<activity
android:name="videoplayer"
android:theme="@android:style/Theme.Holo"
android:launchMode="singleTop"
android:configChanges="keyboardHidden|orientation"/>
Run Code Online (Sandbox Code Playgroud)
活动
// Setup action bar
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
View customActionBarView = getLayoutInflater().inflate(R.layout.player_custom_action_bar, null);
actionBar.setCustomView(customActionBarView,
new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
R.dimen.action_bar_height));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
Run Code Online (Sandbox Code Playgroud)
菜单
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/button1"
android:icon="@drawable/button1"
android:showAsAction="always"/>
<item
android:id="@+id/button2"
android:icon="@drawable/button2"
android:showAsAction="always"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
自定义ActionBar视图
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:background="@color/TranslucentBlack">
<!--Home icon with arrow-->
<ImageView
android:id="@+id/home"
android:src="@drawable/home"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
<!--Another image-->
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:visibility="visible"/>
<!--Text if no image-->
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:visibility="gone"/>
<!--Title--> …Run Code Online (Sandbox Code Playgroud) android android-3.0-honeycomb android-4.0-ice-cream-sandwich android-actionbar android-5.0-lollipop
我一直在撞墙一段时间试图让maven,robolectric,actionbar sherlock和intellij,所有人都玩得很好.我现在已经放弃了使用intellij构建并且专注于maven.
当我跳过maven构建中的测试时,我有一个带有操作栏的应用程序(这告诉我,我很高兴继续使用ActionBar集成前端).IntelliQ构建在ManifestParsingTest.java上失败,抱怨它不知道junit在哪里(以及其他问题).
Robolectric集成
我已经在项目中成功运行了Robolectric.我将Jake Wharton的要点中的文件复制到了src/test/java/com/blah/blah/support/(除了ShadowSherlockFragmentActivity.java它存在src/test/java/com/blah/blah/support/shadows/)并将此行放在我的自定义测试运行器的构造函数中(位于support文件夹中):
ActionBarSherlock.registerImplementation(ActionBarSherlockRobolectric.class);
Run Code Online (Sandbox Code Playgroud)
mvn错误
我遇到了这些构建错误(IntelliJ也有相同的红色波浪形):
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:testCompile (default-testCompile) on project Blah: Compilation failure: Compilation failure:
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/SherlockResourceLoader.java:[29,9] cannot find symbol
[ERROR] symbol : constructor ResourceLoader(int,java.lang.Class,java.util.List<java.io.File>,java.io.File)
[ERROR] location: class com.xtremelabs.robolectric.res.ResourceLoader
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/SherlockResourceLoader.java:[45,5] method does not override or implement a method from a supertype
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/ActionBarSherlockTestRunner.java:[39,37] resourceLoaderForRootAndDirectory has private access in com.xtremelabs.robolectric.RobolectricTestRunner
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/ActionBarSherlockTestRunner.java:[47,30] cannot find symbol
[ERROR] symbol : method getResourcePath()
[ERROR] location: …Run Code Online (Sandbox Code Playgroud) 我正在将自定义小部件集成到我的项目中.它使用自定义属性并且正在崩溃Robolectric.从我收集的内容来看,还不支持自定义属性.注意:构造函数是"敌对的",因为它会在构造时抛出异常,但我现在已将它们注释掉了.
崩溃日志
java.lang.RuntimeException:在com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:82)的com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:106)中错误膨胀layout/main com.xtremelabs.robolectric.res.ViewLoader.inflateView(ViewLoader.java:86)位于com.xtremelabs.robolectric.res.ResourceLoader.inflateView(ResourceLoader.java:377)com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate( ShadowLayoutInflater.java:43)位于com.xtremelabs.robolectric.shadows.ShadowActivity.setContentView的android.view.LayoutInflater.inflate(LayoutInflater.java)中的com.xtremelabs.robolectric.shadows.ShadowLayoutInflater.inflate(ShadowLayoutInflater.java:48) (ShadowActivity.java:101)位于com.blah.MainActivity.estCreate(MainActivity.java:17)的com.blah.MainActivityTest.setUp(MainActivityTest.java:29)上的android.app.Activity.setContentView(Activity.java)在org.junit.interna的org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:44)l.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)org.junit.internal.runners.statements.RunBefores.evaluate( RunBefores.java:27)
引起:java.lang.ClassCastException:com.blah.support.shadows.ShadowMultiDirectionSlidingDrawer无法转换为com.xtremelabs.robolectric.Robolectric.shadowOf(Robolectric.java:857)的com.xtremelabs.robolectric.shadows.ShadowView位于com.xtremelabs.robolectric.shadows.ShadowViewGroup.addView(ShadowViewGroup.java:60)的android.view.ViewGroup.addView(ViewGroup.java)中的.xtremelabs.robolectric.shadows.ShadowViewGroup.addView(ShadowViewGroup.java:70)at com.xtremelabs.robolectric.res.ViewLoader上的com.xtremelabs.robolectric.res.ViewLoader $ ViewNode.addToParent(ViewLoader.java:217)中的android.view.ViewGroup.addView(ViewGroup.java)$ ViewNode.create(ViewLoader. java:180)at com.xtremelabs.robolectric.res.ViewLoader $ ViewNode.inflate(ViewLoader.java:150)at com.xtremelabs.robolectric.res.ViewLoader $ ViewNode.inflate(ViewLoader.java:153)at com.xtremelabs .robolectric.res.ViewLoader.inflateView(ViewLoader.java:102)... 29更多
我正在努力解决这个问题,因为我不太关心测试这个小部件.基本上我希望我的测试不会崩溃并验证视图元素是否出现在屏幕上.
有人建议将java文件放在android包中,但我不确定它是否适用于我的情况.正如这个答案所暗示的那样,自定义小部件存在于"android"包中,它与我的com.blah结构平行.
我创建了一个小部件的阴影来解决敌意问题(但目前我只是注释掉异常抛出).最初我想绕过构造函数中正在进行的工作,因为它依赖于Robolectric未正确报告的属性.阴影构造函数被调用,但它继续通过正常的构造函数执行.有没有办法绕过额外的建设?
ShadowClass
@Implements (MultiDirectionSlidingDrawer.class)
public class ShadowMultiDirectionSlidingDrawer
{
public void __constructor__( Context context, AttributeSet attrs )
{
}
public void __constructor__( Context context, AttributeSet attrs, int defStyle )
{
}
}
Run Code Online (Sandbox Code Playgroud)
自定义测试运行器
public class CustomTestRunner extends RobolectricTestRunner
{
public CustomTestRunner( Class<?> testClass ) throws InitializationError
{
super( testClass …Run Code Online (Sandbox Code Playgroud)