DialogFragment 生命周期
I/### DialogF: onCreate 1
I/### DialogF: onGetLayoutInflater 2
I/### DialogF: onCreateDialog 3
I/### DialogF: onCreateView 4
I/### DialogF: onStart 5
I/### DialogF: onResume 6
I/### DialogF: onCancel 7
I/### DialogF: onPause 8
I/### DialogF: onStop 9
I/### DialogF: onDestroyView 10
I/### DialogF: onDestroy 11
I/### DialogF: onDetach 12
2019年8月5日月曜日
2019年5月22日水曜日
在自定义的SurfaceView 上打开 DialogFragment
在自定义的SurfaceView 上打开 DialogFragment
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean show = true;
if (show) {
AboutDialog aboutDialog = new AboutDialog(getContext());
aboutDialog.show();
Toast.makeText(getContext(), "xxxxxxxxxx", Toast.LENGTH_SHORT).show();
} else {
MyDialogFragment myDialogFragment = new MyDialogFragment();
myDialogFragment.item("99");
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
}
return true;
}
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean show = true;
if (show) {
AboutDialog aboutDialog = new AboutDialog(getContext());
aboutDialog.show();
Toast.makeText(getContext(), "xxxxxxxxxx", Toast.LENGTH_SHORT).show();
} else {
MyDialogFragment myDialogFragment = new MyDialogFragment();
myDialogFragment.item("99");
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
}
return true;
}
2019年3月21日木曜日
ldpi,mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi
ldpi,mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi
float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;
https://blog.csdn.net/guolin_blog/article/details/50727753
https://developer.android.com/reference/android/util/DisplayMetrics.html
float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;
https://blog.csdn.net/guolin_blog/article/details/50727753
https://developer.android.com/reference/android/util/DisplayMetrics.html
ラベル:
Android_Layout
2018年11月12日月曜日
AboutDialog の追加
AboutDialog の追加
public class AboutDialog extends AlertDialog {
private Context context;
public AboutDialog(Context context) {
super(context);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout li = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.about_layout, null);
TextView textView = li.findViewById(R.id.textView3);
textView.setText(Html.fromHtml("<u>" + getString(R.string.GooglePlayStore) + "<u>"));
Pattern pattern = Pattern.compile("");
String url = getString(R.string.PlayURL);
Linkify.addLinks(textView, pattern, url, null, null);
setContentView(li);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="30dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@mipmap/ic_launcher_foreground" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/app_name"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/kankanla"
android:textSize="20dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/GooglePlayStore"
android:textSize="20dp" />
</LinearLayout>
public class AboutDialog extends AlertDialog {
private Context context;
public AboutDialog(Context context) {
super(context);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout li = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.about_layout, null);
TextView textView = li.findViewById(R.id.textView3);
textView.setText(Html.fromHtml("<u>" + getString(R.string.GooglePlayStore) + "<u>"));
Pattern pattern = Pattern.compile("");
String url = getString(R.string.PlayURL);
Linkify.addLinks(textView, pattern, url, null, null);
setContentView(li);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="30dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@mipmap/ic_launcher_foreground" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/app_name"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/kankanla"
android:textSize="20dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/GooglePlayStore"
android:textSize="20dp" />
</LinearLayout>
ラベル:
Android_Layout
2017年6月28日水曜日
android app中如何获取电源锁保持屏幕常亮
android app中如何获取电源锁保持屏幕常亮
protected void screen_on() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
protected void screen_off() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
2017年6月4日日曜日
android 屏幕旋转
android 屏幕旋转
android:screenOrientation="portrait">
纵向方向(显示的高度大于宽度)。
https://developer.android.com/guide/topics/manifest/activity-element.html
2017年1月23日月曜日
Android Dialog Title 非显现
Android Dialog Title 非显现
protected void dia() {
NDaig nDaig = new NDaig(this);
nDaig.requestWindowFeature(Window.FEATURE_NO_TITLE);
nDaig.show();
}
protected void dia() {
NDaig nDaig = new NDaig(this);
nDaig.requestWindowFeature(Window.FEATURE_NO_TITLE);
nDaig.show();
}
2016年12月1日木曜日
Android getDrawable,getColor 过时的替代方法
Android getDrawable,getColor 过时的替代方法
public class ContextCompat{}
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.activity_main);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
relativeLayout.addView(linearLayout);
for (int i = 0; i < 3; i++) {
ImageView imageView = new ImageView(this);
// 过时
// imageView.setImageDrawable(getDrawable(R.drawable.android));
// 替代方法
imageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.firefox));
TextView textView = new TextView(this);
textView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.holo_orange_dark));
textView.setText(String.valueOf(i));
imageView.setId(i);
textView.setId(i);
linearLayout.addView(imageView);
linearLayout.addView(textView);
imageView.setOnClickListener(this);
textView.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
String idinfo = "";
switch (v.getId()) {
case 1:
idinfo = "Button1";
break;
case 2:
idinfo = "Button2";
break;
case 0:
idinfo = "Button1";
break;
}
Toast.makeText(this, idinfo, Toast.LENGTH_SHORT).show();
}
}
public class ContextCompat{}
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.activity_main);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
relativeLayout.addView(linearLayout);
for (int i = 0; i < 3; i++) {
ImageView imageView = new ImageView(this);
// 过时
// imageView.setImageDrawable(getDrawable(R.drawable.android));
// 替代方法
imageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.firefox));
TextView textView = new TextView(this);
textView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.holo_orange_dark));
textView.setText(String.valueOf(i));
imageView.setId(i);
textView.setId(i);
linearLayout.addView(imageView);
linearLayout.addView(textView);
imageView.setOnClickListener(this);
textView.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
String idinfo = "";
switch (v.getId()) {
case 1:
idinfo = "Button1";
break;
case 2:
idinfo = "Button2";
break;
case 0:
idinfo = "Button1";
break;
}
Toast.makeText(this, idinfo, Toast.LENGTH_SHORT).show();
}
}
2016年11月29日火曜日
Android_Layout 用代码得到对象的高宽
Android_Layout 用代码得到对象的高宽
当设定 ViewGroup.LayoutParams 的设定优先。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = new Button(getApplicationContext());
button.setText("Button");
// ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(500, 500);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
button.setHeight(400);
button.setWidth(400);
// viewGroup.addView(button);
viewGroup.addView(button, layoutParams);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout.LayoutParams rl = (RelativeLayout.LayoutParams) ((Button) v).getLayoutParams();
System.out.println(rl.height);
System.out.println(rl.width);
System.out.println(((Button) v).getHeight());
System.out.println(((Button) v).getWidth());
}
});
}
当>>>>
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(500, 500);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
button.setHeight(400);
button.setWidth(400);
viewGroup.addView(button, layoutParams);
结果
I/System.out: 500
I/System.out: 500
I/System.out: 500
I/System.out: 500
当>>>>
button.setText("Button");
// ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(500, 500);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
button.setHeight(400);
button.setWidth(400);
viewGroup.addView(button);
结果
I/System.out: -2
I/System.out: -2
I/System.out: 400
I/System.out: 400
当设定 ViewGroup.LayoutParams 的设定优先。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = new Button(getApplicationContext());
button.setText("Button");
// ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(500, 500);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
button.setHeight(400);
button.setWidth(400);
// viewGroup.addView(button);
viewGroup.addView(button, layoutParams);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout.LayoutParams rl = (RelativeLayout.LayoutParams) ((Button) v).getLayoutParams();
System.out.println(rl.height);
System.out.println(rl.width);
System.out.println(((Button) v).getHeight());
System.out.println(((Button) v).getWidth());
}
});
}
当>>>>
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(500, 500);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
button.setHeight(400);
button.setWidth(400);
viewGroup.addView(button, layoutParams);
结果
I/System.out: 500
I/System.out: 500
I/System.out: 500
I/System.out: 500
当>>>>
button.setText("Button");
// ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(500, 500);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
button.setHeight(400);
button.setWidth(400);
viewGroup.addView(button);
结果
I/System.out: -2
I/System.out: -2
I/System.out: 400
I/System.out: 400
Android_Layout 用代码添加对象
Android LayoutParams
用代码添加对象(按键),并设置LayoutParames,
当按键Click时,变更LayoutParames 的值。
public class MainActivity extends AppCompatActivity {
/**
* https://www.youtube.com/watch?v=QSsvUbPVHOU&index=3&list=PLTstZD3AK3S9sR6uiKzmNtgnY5p4nMT3Z
*
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = new Button(getApplicationContext());
button.setText("Button");
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
// "NG>>" ViewGroup viewGroup = (ViewGroup) findViewById(R.layout.activity_main);
viewGroup.addView(button, layoutParams);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout.LayoutParams layoutParams1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
((Button) v).setLayoutParams(layoutParams1);
// java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
// "NG>>" ViewGroup.LayoutParams layoutParams1 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// Button bbt = (Button) v;
// bbt.setLayoutParams(layoutParams1);
}
});
}
}
用代码添加对象(按键),并设置LayoutParames,
当按键Click时,变更LayoutParames 的值。
public class MainActivity extends AppCompatActivity {
/**
* https://www.youtube.com/watch?v=QSsvUbPVHOU&index=3&list=PLTstZD3AK3S9sR6uiKzmNtgnY5p4nMT3Z
*
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = new Button(getApplicationContext());
button.setText("Button");
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.activity_main);
// "NG>>" ViewGroup viewGroup = (ViewGroup) findViewById(R.layout.activity_main);
viewGroup.addView(button, layoutParams);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout.LayoutParams layoutParams1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
((Button) v).setLayoutParams(layoutParams1);
// java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams
// "NG>>" ViewGroup.LayoutParams layoutParams1 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// Button bbt = (Button) v;
// bbt.setLayoutParams(layoutParams1);
}
});
}
}
登録:
投稿 (Atom)