आप अपने कस्टम दृश्य घोषणा कर सकते हैं और here वर्णित कस्टम विशेषताओं को लागू करें।
परिणाम इस के समान दिखेगा: अपने लेआउट में
<my.package.CustomWebView
custom:url="@string/myurl"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
अपने attr.xml में
<resources>
<declare-styleable name="Custom">
<attr name="url" format="string" />
</declare-styleable>
</resources>
अंत में अपने कस्टम वेब दृश्य कक्षा में
public class CustomWebView extends WebView {
public CustomWebView(Context context, AttributeSet attributeSet) {
super(context);
TypedArray attributes = context.getTheme().obtainStyledAttributes(
attributeSet,
R.styleable.Custom,
0, 0);
try {
if (!attributes.hasValue(R.styleable.Custom_url)) {
throw new RuntimeException("attribute myurl is not defined");
}
String url = attributes.getString(R.styleable.Custom_url);
this.loadUrl(url);
} finally {
attributes.recycle();
}
}
}
नाम _layout_ xml फ़ाइल पर ध्यान दें। मुझे नहीं लगता कि xml से ऐसा करने का कोई तरीका है। मैं आपका बिंदु देखता हूं, आप इसे कोड से यूआरएल लोड किए बिना डिवाइस पर डेटा के साथ लोड करने में सक्षम होना चाहते हैं, लेकिन मुझे नहीं लगता कि अब इसके लिए कोई समर्थन है। –
मेरी बात देखने के लिए Cant0na पर लक्ष्य! –