0

即時通訊嘗試爲我的Android應用程序構建一個Popup。它應該是一個不使用整個屏幕的活動,屏幕右側只有200dp,其餘的應該是透明的黑色。 http://i.stack.imgur.com/6APy6.png具有透明背景和動作欄的Android活動?

的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> 

風格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> 

所以我只需要調整和動作條......請幫助:)

回答

0

轉到Android清單file-> search for the required activity->包括此:

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

這樣的活動標籤:

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

getActionBar()返回null !!!!!!!。您必須使用 –

+0

:this.requestWindowFeature(Window.FEATURE_ACTION_BAR);在設定上述主題之後的活動中 –

0

假設你的活動佈局是的LinearLayout裏面,從左至右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> 
2

你可以沒有標題欄和動作條在清單的主題胡亞蓉作爲

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

和外行出

  1. 爲transperancy你的基地佈局的背景將是android:background="@android:color/transparent"
  2. 您的容器佈局將 設計按您的要求與android:layout_alignParentRight="true"
+0

但我仍然想要操作欄,所以NoTitleBar不適合我。 – littelteddy

+0

請檢查鏈接http://stackoverflow.com/questions/20455314/how-to-make-the-actionbar-transparent – NullPointerException

相關問題