简体   繁体   English

在Android Studio中使用style.xml删除alertDialog的标题

[英]Deleting title of alertDialog using style.xml in Android Studio

在此处输入图片说明

I'd like to delete "Taboo", which is the title of my alertDialog!! 我想删除“ Taboo”,这是我的alertDialog的标题! How should I do that??? 我应该怎么做??? Additionally, could you give a tip of expanding the size of alertDialog also?? 另外,您能不能给一个提示来扩大AlertDialog的大小?

This is my style.xml 这是我的style.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="ActivityTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
</style>

THis is my manifest.xml 这是我的manifest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SettingActivity"
        android:theme="@style/ActivityTheme">
    </activity>
</application>

This is my MainActivity.java code 这是我的MainActivity.java代码

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


    ListView listView = findViewById(R.id.listView);
    adapter = new MenuAdapter();

    adapter.addItem(new ItemsOfMenu(R.drawable.home,"Home"));
    adapter.addItem(new ItemsOfMenu(R.drawable.drawer,"All"));
    adapter.addItem(new ItemsOfMenu(R.drawable.star,"Favorite"));
    adapter.addItem(new ItemsOfMenu(R.drawable.megaphone,"New"));
    adapter.addItem(new ItemsOfMenu(R.drawable.plus,"Custom"));
    adapter.addItem(new ItemsOfMenu(R.drawable.settings,"Settings"));
    adapter.addItem(new ItemsOfMenu(R.drawable.shop,"Store"));

    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectedItem = position;
            adapter.notifyDataSetChanged();

            if(position == 5){

                Intent intent = new Intent(getApplicationContext(),SettingActivity.class);
                startActivityForResult(intent,101);

            }
        }
    });

    GridView gridView = findViewById(R.id.gridView);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
        if(requestCode ==101 && resultCode == RESULT_OK){

        }
}

class MenuAdapter extends BaseAdapter{
    ArrayList<ItemsOfMenu> items = new ArrayList<>();

    @Override
    public int getCount() {
        return items.size();
    }

    public void addItem(ItemsOfMenu item){
        items.add(item);
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MenuListView view;
        if(convertView == null)
            view = new MenuListView(getApplicationContext());
        else view = (MenuListView) convertView;

        if(position == selectedItem){
            view.setBackgroundColor(Color.WHITE);
        } else view.setBackgroundColor(Color.parseColor("#e0e0e0"));

        view.setImageView(items.get(position).getResId());
        view.setTextView(items.get(position).getMenu());

        return view;
    }
}

} }

can be changed by adding a whole new style e.g/...
<style name="CustomAlertDialog" parent="android:Theme.Dialog.Alert">
  <item name="android:windowBackground">@drawable/color_panel_background</item><!-- Used for the buttons -->
    <item name="colorAccent">@color/colorAccent</item>
    <!-- Used for the title and text -->
    <item name="android:textColorPrimary">#FFFFFF</item>
    <!-- Used for the background -->
    <item name="android:background">@color/teal</item>
 </style>
and while initalizing also initialize this theme using ContextThemeWrapper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM