2013-10-29 27 views
0

我在我的項目中集成了zxing。我需要在掃描活動上顯示一條消息。我已使用intent.putExtra("PROMPT_MESSAGE","My custom text");在佈局底部顯示的活動上顯示消息。如何在佈局上顯示兩條消息。可能嗎?在zxing條碼掃描器上添加兩條短信/提示信息

謝謝。

+0

我不確定這是可能的。如何使用'\ n'? '「我的自定義文本1 \ n自定義文本2」 –

回答

0

實測值回答

我修改XML佈局斑馬線的capture.xml。在佈局中添加了另一個Textview,如下所示。

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|center_horizontal" android:background="@color/transparent" android:text="Text 2" android:textColor="@color/status_text" android:textSize="20sp"/>

我可以顯示在頂部的文本。

0

對於其他人來說,這可能很有趣。以下步驟允許在zxing的掃描版面上的任何位置添加文本。

  1. 創建從CaptureActivity
  2. 延伸下面的代碼添加到onCreate方法

    public class ExtendedCaptureActivity extends CaptureActivity { 
    
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
    
        ViewGroup rootView = (ViewGroup) findViewById(android.R.id.content); 
        TextView et = new TextView(this); 
        et.setText("Veuillez scanner le code-barres comportant \nde 12 à 14 chiffres."); 
        et.setTextColor(Color.WHITE); 
        et.setGravity(Gravity.CENTER); 
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
         FrameLayout.LayoutParams.WRAP_CONTENT, 
         FrameLayout.LayoutParams.WRAP_CONTENT); 
        params.gravity = Gravity.CENTER_HORIZONTAL; 
        params.topMargin = 150; 
    
        rootView.addView(et,params); 
    
        } 
    } 
    
  3. 呼叫該意圖以顯示掃描活動的活動。

獲取掃描活動的根視圖,然後可以添加所需的視圖。請享用 !