简体   繁体   中英

Android Activity with transparent background and Action Bar?

im trying to build a Popup for my Android App. It should be a Activity which doesn't use the whole screen, just 200dp on the right side of the screen and the rest should be transparent black.

A Picture of what it looks like / what i want to have: http://i.stack.imgur.com/6APy6.png

Java:

public class ActivitySettings extends BaseActivity implements View.OnTouchListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        setFinishOnTouchOutside(true);
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        System.out.println("Klicked " + motionEvent.getAction());
        // If we've received a touch notification that the user has touched
        // outside the app, finish the activity.
        if (MotionEvent.ACTION_OUTSIDE == motionEvent.getAction()) {
            finish();
            return true;
        }
        return false;
    }
}

AndroidManifest:

    <activity
        android:name="com.cleverlize.substore.test.ActivitySettings"
        android:label="@string/title_activity_settings"
        android:theme="@style/Theme.Transparent">
    </activity>

Style XML:

<style name="Theme.Transparent" parent="Theme.AppCompat.Light">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@color/itemPremium</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>

So i just need the adjustment and the ActionBar... please Help :)

You can have acitivity without titlebar and actionbar in manifest with the theme as

 <activity
            android:name="com.demo.YourActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

and for layout

  1. for transperancy your base layout background will be android:background="@android:color/transparent"
  2. your container layout will be design as per your requirement with android:layout_alignParentRight="true"

Suppose your Activity layout is inside the LinearLayout, set the inner layout margin from left 200sp:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="200sp"
        android:background="#FFFFFF"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Text Display"
            android:textColor="#000000" />
    </LinearLayout>
</LinearLayout>

Go to Android manifest file-> search for the required activity-> include this:

<--android:theme="@android:style/Theme.Translucent"-->

in the activity tag like this:

<activity
           android:name=".Services"
           android:label="@string/title_activity_services"
           android:theme="@android:style/Theme.Translucent" >
</activity>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM