Bonjour à tous,
Je suis entrain de créer un projet sous android studio.
Au début j'ai créer une vue avec xml à travers laquel elle nous emmène vers une autre vue XSLT.
Pour faire une vue xslt,j'ai classer des données dans le fichier xml que je les ai récupéré à travers le fichier xslt et j'ai ajouté ensuite un autre fichier css pour le design de la page
le problème c'est qu'il ne reconnait pas le fichier css et même les images que je les ai définis aussi dans le fichier xml comme ceci:
Voici le code java de la 2ème activity xslt:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
public class LoadXSLTinWebview extends Activity {
 
 WebView webview;
 /** Called when the activity is first created. */
   @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    WebView webview = new WebView(this);
    setContentView(webview);
     webview.loadUrl("C:/Users/Admin/AndroidStudioProjects/Oranguide/app/src/main/assets/cin2.css");
    //Reading XSLT
    String strXSLT = GetStyleSheet(R.raw.cinemaxsl);
    //Reading XML
    String strXML = GetStyleSheet(R.raw.cinemaxml);
    /*
     * Loading XSLT...
     */
    //Transform ...
    String html=StaticTransform(strXSLT, strXML);
    //Loading the above transformed XSLT in to Webview...
    webview.loadData(html,"text/html","utf-8");
}
 
/*
 * Transform XSLT to HTML string
 */
public static String StaticTransform(String strXsl, String strXml) {
    String html = "";
 
    try {
 
        InputStream ds = null;
        ds = new ByteArrayInputStream(strXml.getBytes("UTF-8"));
 
        Source xmlSource = new StreamSource(ds);
 
        InputStream xs = new ByteArrayInputStream(strXsl.getBytes("UTF-8"));
        Source xsltSource = new StreamSource(xs);
 
        StringWriter writer = new StringWriter();
        Result result = new StreamResult(writer);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer(xsltSource);
        transformer.transform(xmlSource, result);
 
        html = writer.toString();
 
        ds.close();
        xs.close();
 
        xmlSource = null;
        xsltSource = null;
 
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (TransformerConfigurationException e) {
        e.printStackTrace();
    } catch (TransformerFactoryConfigurationError e) {
        e.printStackTrace();
    } catch (TransformerException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
 
    return html;
}
 
/*
 * Read file from res/raw...
 */
private String GetStyleSheet(int fileId) {
    String strXsl = null;
 
    InputStream raw = getResources().openRawResource(fileId);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    int size = 0;
    // Read the entire resource into a local byte buffer.
    byte[] buffer = new byte[1024];
    try {
        while ((size = raw.read(buffer, 0, 1024)) >= 0) {
            outputStream.write(buffer, 0, size);
        }
        raw.close();
 
        strXsl = outputStream.toString();
 
        Log.v("Log", "xsl ==> " + strXsl);
    } catch (IOException e) {
        e.printStackTrace();
    }
 
    return strXsl;
 
}
 
}
et voici le code MainActivity
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
public class MainActivity extends AppCompatActivity {
 
    Button btn;
    WebView Webview1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Cliquer();
            }
        });
 
 
    }
 
    public void Cliquer() {
        Intent intent = new Intent(this,LoadXSLTinWebview.class);
        startActivity(intent);
    }
 
}
Voici ce qui est affiché sur écran:
Pièce jointe 466992

Pouvez-vous me proposer une solution pour qu'il puisse reconnaître les fichiers css et les images
Merci à tous.