小编Sha*_*dul的帖子

访问在theme和attrs.xml android中定义的资源

我有一个场景,我想Drawable根据定义的主题设置一个.

为了进一步解释这一点,以下是我在代码中的内容:

\ RES \值\ attrs.xml

<resources>
    <declare-styleable name="AppTheme">
        <attr name="homeIcon" format="reference" />
    </declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)

水库\值\ styles.xml

<resources>
    <style name="AppTheme" parent="android:style/Theme">
        <item name="attr/homeIcon">@drawable/ic_home</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

    <application android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
Run Code Online (Sandbox Code Playgroud)

因此,您已经注意到我正在定义自定义attr homeIcon并在AppTheme中设置属性值.

当我在布局XML中定义此属性并尝试访问它时,它可以顺利运行

<ImageView android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="?attr/homeIcon" />
Run Code Online (Sandbox Code Playgroud)

并将Drawableic_home 呈现为ImageView.

但我无法弄清楚如何以Drawable编程方式访问.

我尝试通过定义持有者来解决LayerList Drawable这个问题,导致资源未找到异常:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:drawable="?attr/homeIcon" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)

总结 我想以编程方式访问Drawable …

resources android attributes themes drawable

34
推荐指数
2
解决办法
2万
查看次数

带有IFRAME android的WebView

我想在<IFRAME>里面加载一个HTML WebView,但我不知道为什么,它无法这样做.

我正在使用以下代码加载 <IFRAME>

webView.loadData("<iframe src=\"http://www.google.com\"></iframe>", "text/html",
                "utf-8");
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的.

WebSettings webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setPluginsEnabled(true);
webViewSettings.setBuiltInZoomControls(true);
webViewSettings.setPluginState(PluginState.ON);
Run Code Online (Sandbox Code Playgroud)

我已经提到了互联网许可:

<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)

我也尝试过设置WebViewClient,shouldOverrideUrlLoading总是返回false.

但它只是不起作用.

我尝试过不同的网站,即google.com以外的网站.

我正在测试这个,三星Nexus S运行ICS 4.0.3

iframe android load webview

11
推荐指数
2
解决办法
5万
查看次数

标签 统计

android ×2

attributes ×1

drawable ×1

iframe ×1

load ×1

resources ×1

themes ×1

webview ×1