ActivityIndicator in react native similar as ProgressBar in android is used to show a round Loading Indicator while loading JSON from background. ActivityIndicator can be modified in size and color, now developers can modify the style of ActivityIndicator and change its size and color. So in this tutorial we would going to create react native app to Change ActivityIndicator color in React Native Android iOS app example tutorial.
Live Screenshot in Android device:
Contents in this project Change ActivityIndicator color in React Native Android iOS Tutorial:
1. Import Platform, StyleSheet, View and ActivityIndicator component in your project.
1
2
3
|
import React, { Component } from ‘react’;
import { Platform, StyleSheet, View, ActivityIndicator} from ‘react-native’;
|
2. We are creating 6 different ActivityIndicator in render’s return block with prop size=’ ‘ and color=’ ‘.
size=’ ‘ : Is used to change the ActivityIndicator size. Available options is small and large.
color=’ ‘ : Is used to change color or background color of ActivityIndicator .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
render()
{
return(
<View style = { styles.MainContainer }>
<ActivityIndicator size=“large” color=“#F44336” />
<ActivityIndicator size=“small” color=“#E91E63” />
<ActivityIndicator size=“large” color=“#00BCD4” />
<ActivityIndicator size=“small” color=“#009688” />
<ActivityIndicator size=“large” color=“#4CAF50” />
<ActivityIndicator size=“small” color=“#FF9800” />
</View>
);
}
|
3. Create Style.
1
2
3
4
5
6
7
8
9
10
11
12
|
const styles = StyleSheet.create(
{
MainContainer:
{
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
paddingTop: ( Platform.OS === ‘ios’ ) ? 20 : 0,
flexDirection: ‘row’,
justifyContent: ‘space-around’,
}
});
|
4. Complete source code for App.js File :
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
|
import React, { Component } from ‘react’;
import { Platform, StyleSheet, View, ActivityIndicator} from ‘react-native’;
export default class Myapp extends Component<{}>
{
render()
{
return(
<View style = { styles.MainContainer }>
<ActivityIndicator size=“large” color=“#F44336” />
<ActivityIndicator size=“small” color=“#E91E63” />
<ActivityIndicator size=“large” color=“#00BCD4” />
<ActivityIndicator size=“small” color=“#009688” />
<ActivityIndicator size=“large” color=“#4CAF50” />
<ActivityIndicator size=“small” color=“#FF9800” />
</View>
);
}
}
const styles = StyleSheet.create(
{
MainContainer:
{
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
paddingTop: ( Platform.OS === ‘ios’ ) ? 20 : 0,
flexDirection: ‘row’,
justifyContent: ‘space-around’,
}
});
|
Screenshot in iOS device :