模仿安卓系统原生的亮度调节框 —>Android弹出框


源码

public class HintActivity extends AppCompatActivity {
    public static final String TAG = "HintActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hint);
    }

    @Override
    protected void onStop() {
        super.onStop();
        Toast.makeText(this,"HintActivity onStop",Toast.LENGTH_SHORT).show();
    }
}


// 布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp"
    android:background="#E40F0F">
    <Button
        android:id="@+id/confirm"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom ="true"
        android:background="#E4DADA"
        android:textSize="35dp"
        android:text="text" />

</RelativeLayout>



public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button hint;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main7);

        hint = findViewById(R.id.hintClick);
        hint.setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.hintClick:
                Toast.makeText(this,"to into HintActivity ",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent("android.intent.action.SHOWHINTACTIVITY");
                startActivity(intent);
                break;
        }
    }
}


// AndroidManifest.xml 配置方式
        <activity
            android:name=".demo1.HintActivity"
            android:excludeFromRecents="true"
            android:exported="true"
            android:theme="@style/Theme.AppCompat.Dialog">
            <intent-filter>
                <action android:name="android.intent.action.SHOWHINTACTIVITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        
        <activity android:name=".demo1.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


参考链接

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/281819.html

(0)
上一篇 2022年8月23日 11:59
下一篇 2022年8月23日 12:40

相关推荐

发表回复

登录后才能评论