这个问题在SO上已经被问了很多,我已经引用了所有的答案.我的导航抽屉上的所选项目仍然保留默认的Holo蓝色背景.我是Java新手,我对"上下文"部分感到困惑.setAdapter().
我的项目是一个Activity,使用导航抽屉交换了多个片段.
这是我的适配器:
mDrawerListView.setAdapter(new ArrayAdapter<String>(
// First parameter - Context
getActionBar().getThemedContext(),
// Second parameter - Layout for the row
R.layout.fragment_navigation_drawer_list_item,
// Third parameter - ID of the TextView to which the data is written
android.R.id.text1,
// Forth - the Array of data
new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
}));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
Run Code Online (Sandbox Code Playgroud)
这里的上下文来自Android Studio中的"预先烹饪"导航抽屉.我认为这将是所选项目的导航抽屉项目背景颜色的答案.所以我改变了我的上下文getActivity().getBaseContext(),,但这并没有改变任何东西.
我的主题(styles.xml):
<resources>
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<!-- Navigation …Run Code Online (Sandbox Code Playgroud) 我正在将Material Design应用到我的带有导航抽屉的应用程序中.在Nav的所有不同实现中.带材料设计的抽屉和工具栏(见本文); 我选择让应用程序感觉类似于ICS/Halo设计,并将Nav Drawer滑出工具栏.问题是当导航抽屉打开时,工具栏会像活动的其余部分一样变暗.如何防止工具栏变暗?如果你在我上面链接的帖子中看到图像,我在#6,3或5之后,但我现在看起来更像#9.
示例(来自上面的帖子):
我在追求什么(工具栏上没有阴影):

我目前得到的(导航抽屉打开时工具栏变暗):

这是我的主要活动的XML的代码:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.funkhaus.navdrawer.app.MainActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar; Added for Material Design -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" />
</FrameLayout>
<fragment android:id="@+id/navigation_drawer" …Run Code Online (Sandbox Code Playgroud) 我正在从 Python 执行 FORTRAN exe。FORTRAN exe 需要几分钟才能完成;因此,我需要在 exe 完成时触发回调。exe 不会向 Python 返回任何内容,但在回调函数中,我将使用 Python 来解析 FORTRAN 的输出文本文件。
为此,我正在使用concurrent.futuresand add_done_callback(),并且它有效。但是网络服务的这一部分,我需要有 Python 方法,该方法subprocess.call() / Popen()在执行 FORTRAN exe 后调用返回。然后当 FORTRAN 完成时调用回调函数。
def fortran_callback(run_type, jid):
return "Fortran finished executing"
def fortran_execute():
from concurrent.futures import ThreadPoolExecutor as Pool
args = "fortran.exe arg1 arg2"
pool = Pool(max_workers=1)
future = pool.submit(subprocess.call, args, shell=1)
future.add_done_callback(fortran_callback(run_type, jid))
pool.shutdown(wait=False)
return "Fortran executed"
Run Code Online (Sandbox Code Playgroud)
fortran_execute() 在提交表单时被调用,我想在不等待 FORTRAN 完成的情况下返回“Fortran 执行”。
目前,Python 方法无需等待 FORTRAN 完成即可返回,但它也会在返回时触发回调。FORTRAN 进程继续运行,当它最终完成时,它尝试调用回调函数并抛出异常,因为future不再存在TypeError: 'NoneType' …