Showing posts with label theme. Show all posts
One of the most coolest things you can add on your activity, is the ability to create a custom popup activity. Follow the steps bellow.
1. We are going to create a layout for our popup activity res/layout/popup_activity.xml the file name does not matter.
2. next create the PopupActivity class to handle any View present on your popup
Note: popup_activity: is the name of our popup layout.
3. we need a theme for our popup, see below.
android:windowIsTranslucent: will make the pop up transparent beyond its borders.
android:windowCloseOnTouchOutside: will close the pop up when you click out side its borders.
4. we need to register our class with the manifest file manifests/AndroidManifest.xml
5. here i will show you how to actually display the popup after a click event.
Note: PopupActivity: is the name of our class.
I hope this was very helpful. Also read how to pass values to your popup activity.
1. We are going to create a layout for our popup activity res/layout/popup_activity.xml the file name does not matter.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.designspaza.carcontroller.PopupActivity" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#555" android:gravity="center" android:orientation="vertical" android:id="@+id/pop_layout"> <TextView android:id="@+id/pop_title" android:layout_width="wrap_content" android:layout_height="50dp" android:background="@android:color/transparent" android:gravity="center_horizontal" android:text="POP1" android:textColor="#fff" android:textSize="20sp" /> <Button android:id="@+id/close_btn" android:layout_width="100dp" android:layout_height="60dp" android:text="Close" /> </LinearLayout>
2. next create the PopupActivity class to handle any View present on your popup
public class PopupActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.popup_activity);
Note: popup_activity: is the name of our popup layout.
3. we need a theme for our popup, see below.
<style name="AppTheme.PopMe" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowCloseOnTouchOutside">true</item> </style>
android:windowIsTranslucent: will make the pop up transparent beyond its borders.
android:windowCloseOnTouchOutside: will close the pop up when you click out side its borders.
4. we need to register our class with the manifest file manifests/AndroidManifest.xml
<activity android:name=".PopupActivity" android:theme="@style/AppTheme.PopMe" />
5. here i will show you how to actually display the popup after a click event.
//details direction for popup button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { Intent i = new Intent(context.getApplicationContext(), PopupActivity.class);
context.startActivity(i);
}
});
Note: PopupActivity: is the name of our class.
I hope this was very helpful. Also read how to pass values to your popup activity.
How To create a pop up Activity on your current Activity
Add a splash screen, is a great way to open you app, especially if its graphics heavy like a game.
first create a xml file under the drawable folder (drawable/splash_screen.xml)
You can add a new theme under your res/values/styles.xml file
NOTE: splash screen will only work if you use the parent theme.AppCompat and your MainActivity class needs to extend the AppCompatActivity class. see below
Now all you have to do is change some lines in you manifests/AdroidManifest.xml file
As you can see, we are telling our app to use the SplashScreenTheme theme when it LAUNCHER. And the SplashScreenTheme reference drable/splash_screen as its windowBackground.
I hope this article has been helpful.
first create a xml file under the drawable folder (drawable/splash_screen.xml)
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <item android:drawable="@color/colorPrimary"/> <!-- Set the Background Image--> <item android:gravity="center" android:width="500dp" android:height="500dp"> <bitmap android:gravity="fill_horizontal|fill_vertical" android:src="@drawable/splash_screen_image"/> </item> </layer-list>
You can add a new theme under your res/values/styles.xml file
<style name="SplashScreenTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name ="android:windowBackground"> @drawable/splash_screen</item> </style>
NOTE: splash screen will only work if you use the parent theme.AppCompat and your MainActivity class needs to extend the AppCompatActivity class. see below
public class MainActivity extends AppCompatActivity {
Now all you have to do is change some lines in you manifests/AdroidManifest.xml file
<activity android:name=".SplashActivity" android:theme="@style/SplashScreenTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" />
As you can see, we are telling our app to use the SplashScreenTheme theme when it LAUNCHER. And the SplashScreenTheme reference drable/splash_screen as its windowBackground.
I hope this article has been helpful.