質問するログイン新規登録

質問編集履歴

1

追記

2017/08/22 07:11

投稿

xoxoo
xoxoo

スコア29

title CHANGED
File without changes
body CHANGED
@@ -25,4 +25,42 @@
25
25
 
26
26
  ###エラーメッセージ
27
27
 
28
- メソッド findViewById(int) は型 xxxService で未定義です。
28
+ メソッド findViewById(int) は型 xxxService で未定義です。
29
+
30
+ ###
31
+ ```java
32
+ @Override
33
+ public int onStartCommand(Intent intent, int flags, int startId) {
34
+
35
+ // inflaterの生成
36
+ LayoutInflater layoutInflater = LayoutInflater.from(this);
37
+
38
+ windowManager = (WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
39
+ WindowManager.LayoutParams params = new WindowManager.LayoutParams(
40
+ WindowManager.LayoutParams.MATCH_PARENT,
41
+ WindowManager.LayoutParams.WRAP_CONTENT,
42
+ WindowManager.LayoutParams. TYPE_SYSTEM_ERROR,
43
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
44
+ | WindowManager.LayoutParams.FLAG_FULLSCREEN
45
+ | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
46
+ | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
47
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
48
+ // | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
49
+ | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
50
+ PixelFormat.TRANSLUCENT);
51
+
52
+ // 最下部に配置
53
+ params.gravity= Gravity.BOTTOM | Gravity.CENTER;
54
+
55
+ //params.x = 20 * dpScale; // 20dp
56
+ // params.y = 100 * dpScale; // 80dp
57
+
58
+ // レイアウトファイルからInfalteするViewを作成
59
+ view = layoutInflater.inflate(R.layout.overlapservice, null);
60
+
61
+ // Viewを画面上に追加
62
+ windowManager.addView(view, params);
63
+
64
+
65
+ ```
66
+ としていてoverlapserviceのレイアウトファイルにはfindViewByIdしたいViewを記述しています。