Issue
I'm trying to create an android Activity
that hooks into the system's ActionProcessText
intent. The goal is to display my Activity
's layout above the currently running application. The Activity
is starting just fine, but it doesn't show up on top of the running application.
Google Translate does this already and I confirmed it does not have the Display over other apps
permission.
Screen recording showing the above in action - https://i.imgur.com/Q9lVI61.mp4
Here is my activity (written using Xamarin):
[Activity(Label = "@string/app_name", Exported = true)]
[IntentFilter(new[] { Intent.ActionProcessText, Intent.CategoryDefault }, DataMimeType = "text/plain")]
public class LookupActivity : Activity
{
public override void OnCreate(Bundle? savedInstanceState, PersistableBundle? persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
var data = this.Intent.GetCharSequenceExtra(Android.Content.Intent.ExtraProcessText);
}
}
and also my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LookupActivity"
android:alpha="0.2">
<TextView
android:id="@+id/msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="16dp"
android:text="Button"
android:onClick="OnButtonClicked"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/msg"
app:layout_constraintVertical_bias="0.025" />
</android.support.constraint.ConstraintLayout>
My thinking was that if I set the Alpha
to something low like 0.2
it would imitate the Google Translate shadow background.
Here is what it looks like when I select my application from the same context menu:
Solution
You can add a style to file styles.xml
as follows:
<style name="AppTheme1" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
<!-- Customize your theme here. -->
<item name="android:windowIsFloating">true</item>
</style>
And apply it to your activity:
[Activity(Label = "@string/app_name", Exported = true,Theme = "@style/AppTheme1" )]
Answered By - Jessie Zhang -MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.