小编Ole*_*vas的帖子

getActionBar()在PreferenceActivity中返回null(AppCompat-v7 21)

PreferenceActivity在v20 sdk示例中提供了DoneBar(操作栏中的两个按钮),但在将SDK和AppCompat更新到版本21后,我的应用程序崩溃了

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayOptions(int, int)' on a null object reference

那是因为getActionBar()返回null.并没有getSupportActionBar()ActionBarActivity.

所以我的问题是如何获取actionbar对象,PreferenceActivity以便我可以在其上应用自定义视图?

解决了

经过一些研究后,我设法通过使用来解决这个问题PreferenceFragment,ActionBarActivity所以我可以打电话getSupportActionBar()

android preferenceactivity

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

自定义首选项标题字体大小大于android 5中的标准首选项

我的应用程序具有自定义布局的自定义首选项,在Android 5上尝试我的应用程序后,我注意到我的自定义首选项看起来与其他首选项不同(字体大小,颜色,填充).所以我认为这将是一个简单的解决方案,只需preference.xml从Android 5 SDK,与我的更改合并并将新布局放到layout-v21文件夹.它修复了填充和颜色问题,但没有更大的标题大小.

我的自定义首选项构造函数如下所示:

public SeekBarPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    setLayoutResource(R.layout.preference_seekbar);
}
Run Code Online (Sandbox Code Playgroud)

preference_seekbar.xml(刚刚将Seekbar添加到原始布局):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="?android:attr/selectableItemBackground" >

    <ImageView
        android:id="@+android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dip"
        android:layout_marginEnd="6dip"
        android:layout_marginTop="6dip"
        android:layout_marginBottom="6dip"
        android:layout_weight="1">

        <TextView android:id="@+android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@+android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/title"
            android:layout_alignStart="@android:id/title"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:maxLines="4" />

        <SeekBar android:id="@+id/seekbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+android:id/title"
            android:layout_toEndOf="@android:id/summary"
            android:layout_toStartOf="@android:id/widget_frame"/>

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. --> …
Run Code Online (Sandbox Code Playgroud)

android android-preferences android-5.0-lollipop

5
推荐指数
1
解决办法
1183
查看次数

错误:导入由webpack构建的模块时,模块"AppModule"导入的"未定义值'未定义'"

我已经使用Webpack构建了Angular2(RC6)模块(尝试了1.x和2.x)并发布到npm但是当我将此模块作为依赖项导入到我的AppModule(导入部分)时,我收到此运行时错误.

如果我使用tsc命令构建,那么我没有收到此错误.我需要Webpack,因为我有html和css文件应该捆绑到js文件中.

如果我在一个捆绑包中构建所有模块,一切正常.

我的webpack.config.js看起来像这样:

const webpack = require('webpack');
const path = require('path');

module.exports = {
    devtool: 'cheap-module-source-map',
    entry: './index.ts',
    output: {
        path: './dist',
        filename: 'index.js'
    },
    resolve: {
      root: [ path.join(__dirname, 'src') ],
      extensions: ['', '.ts', '.js']
    },
    module: {
        loaders: [
          { test: /\.ts$/, loaders: ['awesome-typescript-loader'] },
          { test: /\.(html|css)$/, loader: 'raw-loader' }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

webpack angular

5
推荐指数
0
解决办法
782
查看次数